Use ng-model in nested Angularjs controller

Hadi J

I have two nested controller in angularjs, and want to use ng-model from outer in inner controller. Suppose this

<div ng-controller='outController'>
    // data.Name : from outer controller
    <div ng-controller='innerController'>
         <input type="text" ng-model='name' ng-init='name=data.Name'>
         {{data.Name}} // display this scope value
    </div>
 </div> 

data.Name value display in html page but not bind to name ng-model. How to bind this value to inner ng-model?

Pankaj Parkar

You should follow dot rule in this case, so that will allow you to access the parent scope inside the child scope using prototypal inheritance. For using this approach you need to have an object declared in your parent controller like here it should be declared in outController then the inner controller will not create a new one, it will use the existing one using prototypal inheritance

Markup

<div ng-controller='outController'>
    // data.Name : from outer controller
  <div ng-controller='innerController'>
        <input type="text" ng-model='data.Name'>
  </div>
</div>

Code

app.controller('outController', function($scope){
   $scope.data = {};

   //..other code here ..//

})

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Use ng-model in nested Angularjs controller

From Dev

ng-controller ng-model and $scope how to use angularjs variables everywhere

From Dev

ng-controller ng-model and $scope how to use angularjs variables everywhere

From Dev

angularJS ng-model not updating values in controller

From Dev

AngularJS how to use ng-model inside a custom directive tag, setting the controller dynamically?

From Dev

How to use angularJs filter on ng-model

From Dev

AngularJS use filter with the array of ng-model

From Dev

AngularJS access element from controller in nested ng-repeat

From Dev

AngularJS access element from controller in nested ng-repeat

From Dev

Ionic Framework (AngularJS) Controller cannot see the declared ng-model

From Dev

AngularJS : pass ng-model from directive component to controller

From Dev

How to connect the ng-model of two different controller in angularjs?

From Dev

unable to get ng-model value in controller AngularJS

From Dev

Initializing all ng-model from controller on load Angularjs

From Dev

How to update controller variable with 'ng-model' AngularJS?

From Dev

unable to get ng-model value in controller AngularJS

From Dev

Initializing all ng-model from controller on load Angularjs

From Dev

AngularJS select input ng-model access in controller function

From Dev

Set ng-model value inside the AngularJs Controller

From Dev

Share model with nested controller

From Dev

Share model with nested controller

From Dev

AngularJS Controller not working in nested Controller

From Dev

Controller in Nested views of AngularJS

From Dev

Controller in Nested views of AngularJS

From Dev

How to use checkbox with nested ng-repeat in angularjs

From Dev

Angularjs select ng-change is not triggered when ng-model is initialized in controller

From Dev

How to use ternary operator to change value of ng-model in AngularJS?

From Dev

How to use ternary operator to change value of ng-model in AngularJS?

From Dev

Angularjs ng-model nested inside ng-repeat updates all

Related Related

  1. 1

    Use ng-model in nested Angularjs controller

  2. 2

    ng-controller ng-model and $scope how to use angularjs variables everywhere

  3. 3

    ng-controller ng-model and $scope how to use angularjs variables everywhere

  4. 4

    angularJS ng-model not updating values in controller

  5. 5

    AngularJS how to use ng-model inside a custom directive tag, setting the controller dynamically?

  6. 6

    How to use angularJs filter on ng-model

  7. 7

    AngularJS use filter with the array of ng-model

  8. 8

    AngularJS access element from controller in nested ng-repeat

  9. 9

    AngularJS access element from controller in nested ng-repeat

  10. 10

    Ionic Framework (AngularJS) Controller cannot see the declared ng-model

  11. 11

    AngularJS : pass ng-model from directive component to controller

  12. 12

    How to connect the ng-model of two different controller in angularjs?

  13. 13

    unable to get ng-model value in controller AngularJS

  14. 14

    Initializing all ng-model from controller on load Angularjs

  15. 15

    How to update controller variable with 'ng-model' AngularJS?

  16. 16

    unable to get ng-model value in controller AngularJS

  17. 17

    Initializing all ng-model from controller on load Angularjs

  18. 18

    AngularJS select input ng-model access in controller function

  19. 19

    Set ng-model value inside the AngularJs Controller

  20. 20

    Share model with nested controller

  21. 21

    Share model with nested controller

  22. 22

    AngularJS Controller not working in nested Controller

  23. 23

    Controller in Nested views of AngularJS

  24. 24

    Controller in Nested views of AngularJS

  25. 25

    How to use checkbox with nested ng-repeat in angularjs

  26. 26

    Angularjs select ng-change is not triggered when ng-model is initialized in controller

  27. 27

    How to use ternary operator to change value of ng-model in AngularJS?

  28. 28

    How to use ternary operator to change value of ng-model in AngularJS?

  29. 29

    Angularjs ng-model nested inside ng-repeat updates all

HotTag

Archive