我有一個控制器,它調用執行$ http.get更新指令範圍後,控制器服務呼叫
app.controller('myController', function ($scope, mService) {
$scope.chair;
myService.getData().then(function (data) {
$scope.chair = data.chairID;
});
});
內的控制器範圍的服務,我有我正努力的指令通過在$ scope.chair值:
<section ng-controller="mycontroller">
<my-directive data-chair="chair"></my-directive>
</section>
並在myDirective.js
restrict: 'E',
replace: true,
templateUrl: 'app/some-file.html',
scope: {
chair: '='
},
controller: [ '$scope', function ($scope) {
alert('got chair : ' + $scope.chair);
....
但是,通過上述,我發現警告時('got chair:'+ $ scope.chair)未定義。
內位指示,如果我硬編碼的椅子:
app.controller('myController', function ($scope, mService) {
$scope.chair = 'hello';
myService.getData().then(function (data) {
$scope.chair = data.chairID;
});
});
我的指令將顯示hello
。
您使用的是哪個版本的Angular? – Makoto
使用v1.4.0感謝 –