I have a nested directive (with scope:true, i.e child scope) and I want to broadcast an event from parent to the child. So where should i put the scope.$broadcast() and scope.$on() in the directive, should it be in directive controller or in the link method. my current implementation is as follows:
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);
});
}
};
}]);