Sunday, January 27, 2013

Sharing variable to partial view

Given these tags on main page:


<body ng-app='TheApp' ng-controller='TheController'>
   First <input ng-model='great.message'/>
</body>


And this tag on the partial view:
Second <input ng-model='great.message'/>


First and Second will be in sync with each other if you typed on First first. If you typed on Second first, the model on First input won't sync with the Second.


To correct that, must initialize the model on the First's controller:

function DepartmentController($scope) {
    $scope.great = { message : 'You see' };
}