Javascript 角度仅加载第一个指令
我已通过以下设计模式声明了两个指令:Javascript 角度仅加载第一个指令,javascript,angularjs,angularjs-directive,directive,Javascript,Angularjs,Angularjs Directive,Directive,我已通过以下设计模式声明了两个指令: var sampleDrtv = function () { return { restrict: 'E', replace: true, scope: false, templateUrl: 'app/views/partials/sample.html', link: function() { alert('sample');
var sampleDrtv = function () {
return {
restrict: 'E',
replace: true,
scope: false,
templateUrl: 'app/views/partials/sample.html',
link: function() {
alert('sample');
}
}
};
angular
.module('app')
.directive('sampleDrtv', sampleDrtv);
如果按照此模式添加两条指令,则只加载第一条指令。
有人能解释一下原因吗?
代码片段:您的标记未正确关闭。因此,Angular无法正确解析指令。固定HTML将是:
<div ng-app="ativ">
<ativ-history-list></ativ-history-list>
<ativ-history-detail></ativ-history-detail>
</div>
当前,您的html在创建指令作为元素时会正确关闭指令,而您的html具有。它们不是自动关闭的
<div ng-app="ativ">
<ativ-history-list></ativ-history-list>
<ativ-history-detail></ativ-history-detail>
</div>
@Ghuro很高兴能帮助你..男:)来看看我的编辑。。在这篇文章中,我详细地解释了为什么它不起作用……正如你在问题“生活和学习”中所问的那样;)我以为任何标签都可以自动关闭。再次感谢。@Ghuro您还需要什么吗。?谢谢:)
<div ng-app="ativ">
<ativ-history-list></ativ-history-list>
<ativ-history-detail></ativ-history-detail>
</div>