nul*_*oid 4 javascript angularjs angularjs-directive
所以使用1.20 rc2并尝试实现一个指令:
var directives = angular.module('directives', ['controllers']);
directives.directive("drink", function()
{
return
{
template: '<div>{{flavor}}</div>',
link: function(scope){
scope.flavor = "cherry";
}
}
});
Run Code Online (Sandbox Code Playgroud)
该指令在主JS文件中被调用
var comsumerApp = angular.module('comsumerApp', ['ngRoute','controllers', 'services', 'directives']);
Run Code Online (Sandbox Code Playgroud)
所有控制器都像服务一样工作但是当我尝试这样做时,我得到了这个错误:
"未捕获的SyntaxError:意外的令牌:"
然后我得到了
$ injector:modulerr错误.
注释掉"drink"指令可以阻止这个错误,所以很明显它与:或某事有关.
任何人都可以对这个问题发光,我完全迷失了.
谢谢.
Den*_*nis 12
尝试在开始括号之前删除换行符:
return
{
template: '<div>{{flavor}}</div>',
link: function(scope){
scope.flavor = "cherry";
}
}
Run Code Online (Sandbox Code Playgroud)
对此:
return {
template: '<div>{{flavor}}</div>',
link: function(scope){
scope.flavor = "cherry";
}
}
Run Code Online (Sandbox Code Playgroud)
它可能是由于automatic semicolon insertion,所以你的浏览器插入;后return,因为它认为你只是错过了它..
| 归档时间: |
|
| 查看次数: |
5741 次 |
| 最近记录: |