0
私はネストされたディレクティブ(スコープ:true、つまり、子スコープ)を持っていて、親から子へイベントをブロードキャストしたいと思います。ですから、ディレクティブ内の$ broadcast()とscope。$ on()のスコープは、ディレクティブコントローラまたはリンクメソッドのどこに置くべきですか。次のように 私の現在の実装は次のようになります。私はブロードキャストし、角度指示の中でイベントをキャッシュする必要があります
angular.module('mainApp')
.directive('customElement', [function(){
return {
restrict: 'E',
controller : function ($scope, httpService) {
**var obj = {
url : $scope.url,
contentType : "application/json; charset=utf-8",
responseType : "json",
method : "GET"
};
httpService.makeAjax(obj).then(function (response) {
$scope.$broadcast('ready-to-render', response);
});**
}
};
}])
.directive('testDir', [function(){
return {
restrict: 'E',
replace : true,
template : "<div>{{row | json}}</div>",
controller : function ($scope) {
$scope.$on('ready-to-render', function(e, response) {
$scope.row = response;
console.log(response);
});
}
};
}]);