angularjs - events in angular not binding to vm -


this question has answer here:

i new angular , cant seem figure out.

in controller using var vm = this syntax rather using $scope when trying attach $on event handler vm.$on not function error.

this works:

$scope.$on('$viewcontentloaded', function () {      console.log(vm.myform); }); 

this not:

var vm = this;  vm.$on('$viewcontentloaded', function () {      console.log(vm.myform); }); 

could please explain why.

thanks james

$on method of $rootscope ,you cannot access elsewhere.in angular js,event communication happens through $rootscope.broadcast , $rootscope.emit,to subscribe event can use $rootscope.$on .to know more detail can read

http://toddmotto.com/all-about-angulars-emit-broadcast-on-publish-subscribing/


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -