我是 AngularJS 的新手,看到我所有的 html 代码变得越来越庞大和肮脏,我想做指令来组织它。因此,我从一个小指令开始,您可以在这里看到:
app.module('MyDirectiveModule', [ ])
.directive('TestDirective', function () {
return {
restrict: 'E',
templateUrl: 'test-index.html'
};
});
对于这一小段代码:
<div class="text-center">
<h1>Coding with AngularJs</h1><br><br>
</div>
所以最终结果是(html指令文件为test-index.html):
<body ng-app="testsApp">
<test-index></test-index>
我包含了所有脚本并且检查了所有路径,我仍然不明白为什么它仍然不起作用..
最佳答案
您正在使用 <test-index></test-index>
调用您的指令但你的指令名称是 TestDirective
。您应该使用 <test-directive></test-directive>
来调用它
此外,如果您使用 Angular 1.5,我建议您研究组件而不是指令。这将使向 Angular2 的过渡更加顺利。
关于javascript - AngularJS 自定义指令不生成代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38333948/