의 당신이 두 개의 컨트롤러를 가지고 있다고 가정 해 봅시다 :
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
$scope.another = 'AnotherWorld';
});
app.controller('AnotherCtrl', function($scope) {
});
및 템플릿 :
<div ng-controller="MainCtrl">
<p>{{name}}</p>
<div ng-controller="AnotherCtrl">
<p>{{name}}</p>
<p>{{another}}</p>
</div>
</div>
이름과 다른이 템플릿에 신속하게 업데이트를 참조해야 아이의 범위에 부모로부터 상속됩니다.
현재 서비스 소개 : 서로 이름을 업데이트,
app.service('OnlyAService', function($q, $timeout){
return {
getNewValue: getNewValue
}
function getNewValue() {
var deferred = $q.defer();
$timeout(function(){
deferred.resolve({name: 'NewCrapReplacedWorld', another: 'NewCrapReplacedAnotherWorld'});
}, 2000);
return deferred.promise;
}
});
이 AnotherCtrl에 서비스를 주사를
app.controller('AnotherCtrl', function($scope, OnlyAService) {
OnlyAService.getNewValue().then(function(data){
$scope.another = data.another;
$scope.name = data.name;
});
});
당신은 템플릿 변경에 AnotherCtrl 내의 다른 이름 것을 볼 수 있지만 것 부모를위한 것. 결코 변하지 않을 것입니다. 하나의 해결책은 $ scope. $ parent.name = data.name을 사용하는 것입니다.
소위 스코프 스프가 문제의 원인 일 수 있습니다. 그것을 고치는 다른 방법이 있습니다. 코드가 없으면 추측 할 수있는 영역이 매우 넓습니다.
데이터가 표준 방식으로 컨트롤러에 설정되면 UI가 자동으로 업데이트됩니다. jsfiddle 또는 다른 작동 샘플을 제공하고 제공하십시오. 지정된 설명으로 오류를 판별 할 수있는 방법이 없습니다. –