【发布时间】:2016-02-20 12:29:01
【问题描述】:
我只是 Angular JS 的初学者。我正在学习编写指令。
<!DOCTYPE>
<html ng-app="myapp">
<head>
<script src="angular.min.js"/>
<script>
var app = angular.module('myapp', []);
app.directive('helloWorld',function()
{
return{
restrict: 'AEC',
replace: 'true',
template: '<h1>helloWorld</h1>'
}
});
</script>
</head>
<body>
<h1>Hello World example</h1>
<hello-world></hello-world>
</body>
</html>
现在,上面的代码有什么问题,我收到一个错误 - Uncaught Error: [$injector:modulerr]。
1. 控制器是否必须编写指令,它不是从 $rootscope 继承的。
2. 如何掌握指令。
【问题讨论】:
-
错误是什么?我认为通常模板需要是元素的文本表示——而不是文本节点。把模板改成
'<div>helloWorld</div>'能用吗? -
@mgilson 未捕获错误:[$injector:modulerr]
-
您能否尝试将脚本标签中的“angular.min.js”替换为“ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js”,看看它是否在您的本地工作?
-
@NitinGarg 链接不起作用
-
请在 ajax.google 之前添加 http://...
标签: angularjs angularjs-directive