javascript - Angular run function on broadcast and page load -


i have controller below, .$on attribute called via .$broadcast when form submitted. i'd event run when controller loads. there syntactically easy way go doing this, or have add on page load listener?

myapp.controller('downloadscloudctrl', ['$scope',                                          '$rootscope',                                          'requestservice',   function($scope, $rootscope, requestservice){   $scope.title = 'most popular keywords';   $scope.tooltip = 'test tooltip';   $rootscope.$on('updatedashboard', function(event, month, year) {     requestservice.getp2pkeyworddata(month, year).then(function(data) {       $scope.d3data = data;     });   }); }]); 

if want run when controller loads, extremely simple. remove $on logic own function , call inside controller init:

myapp.controller('downloadscloudctrl', ['$scope', '$rootscope', 'requestservice', function($scope, $rootscope, requestservice){     $scope.title = 'most popular keywords';     $scope.tooltip = 'test tooltip';      var updatedash = function(month, year) {         requestservice.getp2pkeyworddata(month, year).then(function(data) {             $scope.d3data = data;         });     };      $rootscope.$on('updatedashboard', function(event, month, year) {         // run update function         updatedash(month, year);     });      // run update function once when controller loads     updatedash(somemonth, someyear); }]); 

now better abstracted service, should @ least started.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -