Skip to content Skip to sidebar Skip to footer

Use Ng-model In Nested Angularjs Controller

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

Solution 1:

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<divng-controller='innerController'><inputtype="text"ng-model='data.Name'></div></div>

Code

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

   //..other code here ..//

})

Post a Comment for "Use Ng-model In Nested Angularjs Controller"