Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to call $scope.$broadcast when use vm=this? #61

Closed
majj opened this issue Sep 12, 2014 · 4 comments
Closed

how to call $scope.$broadcast when use vm=this? #61

majj opened this issue Sep 12, 2014 · 4 comments
Labels

Comments

@majj
Copy link

majj commented Sep 12, 2014

TypeError: vm.$broadcast is not a function

when publishing and subscribing events using $emit, $broadcast, or $on consider moving these uses to a factory and invoke from the controller.

is there an example?

@johnpapa
Copy link
Owner

if you need the $scope methods, you need to inject $scope.

@dmaslov
Copy link

dmaslov commented Sep 12, 2014

So is it ok to use this and $scope in one controller?

@johnpapa
Copy link
Owner

You can certainly do that. Part of the advantage of using "controller as" is that the $scope does many things. Controller As allows the data binding aspects to remain separate and then we only inject $scope when we need it for something else.

When I need $scope for something in a controller, I try to first see if I really need it, and if I do I abstract it to a service for tings like broadcast/emit. So in your case I would still abstract it.

@dmaslov
Copy link

dmaslov commented Sep 12, 2014

Clear! Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants