angularjs - events in angular not binding to vm -
this question has answer here:
- angular.js “controller …” + $scope.$on 3 answers
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
Post a Comment