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

Angular variables don't work #86

Closed
schickling opened this issue May 15, 2014 · 7 comments
Closed

Angular variables don't work #86

schickling opened this issue May 15, 2014 · 7 comments

Comments

@schickling
Copy link

When I want to use auto injected angular variables such as $route they are not available for bindonce. I guess bindonce really just has access to the $scope and doesn't autoinject on its own.

But this functionality would be really convenient. My current workaround is manually assigning the necessary variables to the $scope.

@Pasvaz
Copy link
Owner

Pasvaz commented May 15, 2014

I'm not sure to understand your question. Bindonce access ony the scope as it is supposed to be and as the ng-* directives do as well. If you want to publish a service's variable into the DOM you should create your own directive and inject the service to it or use the controller to elaborate the value got from the service and make it available to the view, if you don't want to create a new directive you could modify bindonce and inject the service into it but I wouldn't suggest this solution. For what regards the workaround, yes it works and I often see people using that system in their code, however don't abuse of it, things can easily get messy and out of control.

@Pasvaz Pasvaz closed this as completed May 15, 2014
@schickling
Copy link
Author

Simple example:

With angular variable interpolation you can do stuff like that: {{ $route.current.params.myParam }}

For that to work with bindonce, you need to set $scope.$route = $route in your controller. That is not needed with the standard interpolation.

Is this behavior intended? As you set it might get easily messy...

@Pasvaz
Copy link
Owner

Pasvaz commented May 16, 2014

With which version of AngularJs you can do {{ $route.current.params.myParam }} without setting $scope.$route = $route

@schickling
Copy link
Author

I'm using Angular 1.3

@Pasvaz
Copy link
Owner

Pasvaz commented May 16, 2014

Can you provide a working example of what you are stating?
As far as I know no version of Angular allows to access to any provider via data binding but things change fast so, even if I don't think this approach would be compliant with the MVVM architecture, I could be wrong.
You can use plnkr.co or fiddler for the code.

@schickling
Copy link
Author

Oh boy, I tricked my self. You are right! 💫

@Pasvaz
Copy link
Owner

Pasvaz commented May 16, 2014

No problem, it happens 😃

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

No branches or pull requests

2 participants