Pasvaz/bindonce

Angular variables don't work

Closed this issue · 7 comments

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.

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.

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...

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

I'm using Angular 1.3

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.

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

No problem, it happens 😃