question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ng-model vs. child $scope created by translate-attr-placeholder

See original GitHub issue

I 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:closed
  • Created 8 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
rajushcommented, Mar 3, 2016

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!

0reactions
knallicommented, Mar 6, 2016

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.

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found