I have the following code:
Test.html:
<div>Test</div>
<dta-feed my-list="myList"></dta-feed>
TestCtrl.js
angular.element(document).ready(function () {
$scope.loadData();
});
$scope.loadData = function () {
$rootScope.$broadcast("testEvent");
}
dtafeed-directive.js
$scope.$on("testEvent", function () {
console.log('Testing broadcast event');
});
Can anyone help me to know h
Would you like to try?
Test.html:
<div>Test</div>
<dta-feed my-list="myList"></dta-feed>
TestCtrl.js
angular.element(document).ready(function () {
$scope.loadData();
});
$scope.loadData = function () {
$rootScope.$broadcast("testEvent");
}
dtafeed-directive.js
var ev = $rootScope.$on("testEvent", function () {
console.log('Testing broadcast event');
});
$scope.$on('$destroy', function () {
ev();
});
This link helped me to fix the issue Broadcast not received in directive
$timeout(function(){
$scope.$broadcast('testEvent');
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.