私はあちこち検索しましたが、思いつくことができる唯一のことは、コンパイル機能がどのように機能するかについて基本的なことを理解していないということです。
これが私が持っているものです
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
私がここに欠けているものはありますか?コンパイルを正しく使用していますか? マニュアルはそれほど役に立たないようです。