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
  • That is great, thank you very @MichaelRadionov much for pointing me in the right direction. Commented Jun 4, 2015 at 12:35

1 Answer 1

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/

Sign up to request clarification or add additional context in comments.

1 Comment

Hey @vignesh thanks for pointing me to this article. I will take a look.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.