後、私は、コントローラの範囲内でA $ 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)。 contoller内
、私は椅子ハードコーディング場合:
app.controller('myController', function ($scope, mService) {
$scope.chair = 'hello';
myService.getData().then(function (data) {
$scope.chair = data.chairID;
});
});
私のディレクティブはhello
が表示されます。
どのバージョンのAngularを使用していますか? – Makoto
v1.4.0を使用していただきありがとうございます。 –