ng-model vs. child $scope created by translate-attr-placeholder
See original GitHub issueI really searched a lot to try finding some answers, sorry if it is duplicated somehow.
Today I tried to use ng-translate with placeholder using the translate-attr-placeholder directive.
It worked, however, this directive is creating a child $scope and, because of that, the ng-model creates an object inside of each directive $scope, instead of creating in the controller’s $scope:
Example:
<input type="text" ng-model="auth.username" translate translate-attr-placeholder="Username"/>
<input type="password" ng-model="auth.password" translate translate-attr-placeholder="Password"/>
<button ng-click="login(auth)">LOG IN</button>
In this case, the login function receives an undefined auth.
If it’s the normal behavior, no problem, of course that are many ways to deal with nested $scope. I just would like to know if I’m using it wrong?
Thanks a lot!
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
ngModel Changing to Child Scope - angularjs - Stack Overflow
Now both ExampleController.scope and childController.scope have a property val with a value of 2, but they are completely separate and not bound ...
Read more >AngularJS Directive Child Scope – ng-repeat & ng-model
In this blog we will see what is a child scope of a directive and what are its implications. The Problem. As we...
Read more >ngModel - AngularJS: API
The ngModel directive binds an input , select , textarea (or custom form control) to a property on the scope using NgModelController, which...
Read more >AngularJS Scopes: An Introduction - Carbon Five Blog
When AngularJS processes the ng-model directive in the view, it starts listening for change events on that input element and on the scope's...
Read more >Scope creep, a deep dive into Angular's scope
The $rootScope is created on the DOM element where you set up ng-app . ... The ng-model directive will bind input , select...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is something I faced too. I had a similar question posted here: [https://github.com/angular-translate/angular-translate/issues/874]
For now, I’m using filter within the expression of the placeholder
placeholder="{{ 'text' | translate }}"
which binds the scope to the controller, until I find a way to figure it out. I hope there is way to solve this without using a filter.Thanks!
Right. Currently we cannot resolve this without a scope.
Highly recommended: Use always expressions with dots. The controllerAs approach is a very good way! The other way is using the filter.