Javascript 在DOM上执行多个指令
AngularJs1.3中的模块中定义了2条指令 我发现只有一条指令被执行,尽管当另一条指令被注释掉时,这两条指令分别工作。Javascript 在DOM上执行多个指令,javascript,html,angularjs,angularjs-directive,tags,Javascript,Html,Angularjs,Angularjs Directive,Tags,AngularJs1.3中的模块中定义了2条指令 我发现只有一条指令被执行,尽管当另一条指令被注释掉时,这两条指令分别工作。 执行控制台中没有异常 指示 angular.module('studentDetailApp.directives',[]).directive('studentDirective', function () { return { template:'...', link: function ($scope, element, attrs) { c
执行控制台中没有异常 指示
angular.module('studentDetailApp.directives',[]).directive('studentDirective', function () {
return {
template:'...',
link: function ($scope, element, attrs) { console.log('student directive');}
}
})
.directive('basicDirective', function () {
return {
restrict:'E',
template:'custom directive: {{textToInsert}}',
link:function ($scope, element, attrs) { console.log('Printing out custom template');}
}
});
index.html
<html lang="en" ng-app="studentDetailApp">
<head>
....
</head>
<body>
<div ng-controller="StudentController">
<basic-directive/>
<div student-directive></div>
</div>
</body>
</html>
....
我发现第二个指令有效,而第一个指令被忽略。错误是什么?您需要正确地关闭
基本指令元素,如
,元素标记本质上不是自动关闭的,除了img
,br
,hr
等
标记
<div ng-controller="StudentController">
<basic-directive></basic-directive>
<div student-directive></div>
</div>
这是一个输入错误,它应该是
而不是
,有趣的是,这是有效的指令(尽管如此)。它是第一个被忽略的指令。@IUnknown很高兴帮助您。。谢谢:)