Running latest stable version of Angular in latest stable Chrome. I have an ng-click on a DOM element that's inside a view with ng controller A, but the DOM element itself has an ng-controller set to another controller, B. ng-click fires inside controller B, however changes to scope properties, which DOM element is bound to by its ng-model attribute, are not reflected.
Specifically I have a textarea, as well as other HTML5 input types. No errors, and when I break in the debugger, I can look at the scope variable and see that $scope is in fact pointing to controller B.
Plnkr example here, notice how it only updates the input that's inside the same DIV?:
Running latest stable version of Angular in latest stable Chrome. I have an ng-click on a DOM element that's inside a view with ng controller A, but the DOM element itself has an ng-controller set to another controller, B. ng-click fires inside controller B, however changes to scope properties, which DOM element is bound to by its ng-model attribute, are not reflected.
Specifically I have a textarea, as well as other HTML5 input types. No errors, and when I break in the debugger, I can look at the scope variable and see that $scope is in fact pointing to controller B.
Plnkr example here, notice how it only updates the input that's inside the same DIV?: http://plnkr.co/edit/DmccNj?p=preview
Share Improve this question edited Apr 3, 2013 at 0:16 brushleaf asked Apr 2, 2013 at 23:40 brushleafbrushleaf 1,2154 gold badges18 silver badges26 bronze badges 4- 2 Can you post a Plunker or at least some code? – Josh David Miller Commented Apr 2, 2013 at 23:43
- Josh, working on one now. – brushleaf Commented Apr 2, 2013 at 23:54
-
most likely a scope inheritance issue due to using a primitive in scope.... read this and try the
dot
remendation github./angular/angular.js/wiki/… – charlietfl Commented Apr 3, 2013 at 0:02 - Notice how in the Plunker it only updates one of the two inputs, not the one in a different div, even though they have the same controller. – brushleaf Commented Apr 3, 2013 at 0:17
1 Answer
Reset to default 7I had the same issue just recently. Apparently, when you create two HTML fragments with the same ng-controller
, it creates two separate instances of the controller. So, hitting the 'EDIT' button sets $scope.ment
in instance 1, but the input field is bound to instance 2 of the controller.
If you must do it this way, you're best of creating an angular service, as they are singletons.
Here is my question: Splitting HTML ponents for one controller causes controller to stop working
Also, Angular Batarang is a very cool Chrome extension from the AngularJS team to debug Angular applications. I mention this because if you (or I) had used this, we would have instantly seen what was going wrong.