2013-08-26 5 views

답변

5

같은 개체가 두 컨트롤러의 범위에 있어야한다 : 여기

<script> 
    angular.module('foobar', []).controller('ContentCtrl', ['$scope', function($scope) { 
     $scope.content = {'title': 'Foo', 'subtitle': 'Bar', 'text': 'desc'}; 
    }]); 
</script> 

<form action="#" ng-controller="ContentCtrl"> 
    <input type="text" ng-model="content.title"> 
    <input type="text" ng-model="content.subtitle"> 
    <textarea ng-model="content.text"></textarea> 
</form> 

<div ng-controller="ContentCtrl"> 
    <input type="text" ng-model="content.title"> 
    <input type="text" ng-model="content.subtitle"> 
    <textarea ng-model="content.text"></textarea> 
</div> 

는 Plunker이다. http://plnkr.co/edit/ILzGCs9AYiPTETE92KTm?p=preview

원래 예제에서 각 범위에는 자체 개체가 있으며 각 개체는 자체 개체에서 작동합니다. 두 범위가 동일한 개체를 공유하면 각 개체는 동일한 개체에서 작동하므로 한 범위의 변경 사항이 다른 개체에 반영됩니다.

+0

위대한, 정말 간단합니다. 감사! – acme

관련 문제