ディレクティブが作成するスコープにデータを入れようとしています。これが私のjsFiddleです。
次のコードはうまくいきます
.directive('directive1', function () {
return: {
scope: true,
controller: function ($scope) {
$scope.name = 'world';
}
}
})
<div directive1>
<p>{{ name }}</p>
</div>
しかし、これらのコードは機能しません
.directive('directive2', function () {
return: {
scope: true,
controller: function () {
this.name = 'world';
},
controllerAs: 'testCtrl'
}
})
<div directive2>
<p>{{ testCtrl.name }}</p>
</div>
私のコードに何か問題がありますか? または私は何かについて誤解しましたcontrollerAs
か?