【发布时间】:2017-06-02 10:56:49
【问题描述】:
我搜遍了,唯一能想到的就是我不了解编译功能如何工作的基本知识。
这就是我所拥有的
angular.module("app", [])
.directive("foo", function(){
return {
scope: {},
controller: function() {
this.someValue = 23;
},
contollerAs: "ctrl",
compile: function(tElem, tAttrs) {
tElem.html("<h1>Data: {{ctrl.someValue}}</h1>");
},
template: '<h1>test</h1>'
}
});
这显示:数据:,似乎没有看到“someValue”变量。 但是,当我使用范围而不是 controllerAs 语法时,它可以工作。
//this works fine
angular.module("app", [])
.directive("foo", function(){
return {
scope: {},
controller: function($scope) {
$scope.someValue = 23;
},
contollerAs: "ctrl",
compile: function(tElem, tAttrs) {
tElem.html("<h1>Data: {{someValue}}</h1>");
},
template: '<h1>test</h1>'
}
});
这显示:数据:23
我在这里缺少什么吗?我是否正确使用编译? 手册似乎没有那么有用。
【问题讨论】:
标签: javascript angularjs angularjs-directive angularjs-scope angularjs-controlleras