这是我的简单指令:
myApp.directive('myDirective', function() {
var someVar = "Yodelayheehoo";
return {
restrict: 'E',
template: "<p>The var is: {{someVar}}</p>"
}
});
我试过了,但是someVar
没有打印出来。
我错过了什么?
答案 0 :(得分:2)
someVar
必须是范围对象的属性,而不仅仅是局部变量:
myApp.directive('myDirective', function() {
return {
restrict: 'E',
template: "<p>The var is: {{someVar}}</p>",
link: function(scope) {
scope.someVar = "Yodelayheehoo";
}
}
});