0

I am very new to angular and cant seem to figure this out.

In my controller I am using the var vm = this syntax rather than using $scope but when trying to attach an $on event handler I get a vm.$on is not a function error.

This works:

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

This does not:

var vm = this;

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

could some please explain why.

Thanks James

1 Answers1

1

$on is a method of $rootscope ,you cannot access elsewhere.In angular js,event communication happens through $rootscope.broadcast and $rootscope.emit,to subscribe that event only we can use $rootscope.$on .To know more detail about this you can read

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

vignesh
  • 151
  • 6