我更新的對象的resource.save回調中,像這樣:angular.js視圖不更新
$scope.addProfile = function() {
User.save({ "id": user_id }, $scope.createdProfile, function(savedUser, getResponseHeaders) {
//$scope.$apply(function() {
$scope.user = savedUser;
console.debug($scope.user); // I doublechecked that this contains the correct data
//});
});
};
不幸的觀點是不正確更新。正如你所看到的,我已經試圖在apply中包裝這個東西,這會導致錯誤「Error:$ digest already in progress」。所以我評論說,再次出來。
不更新看起來像這樣的看法位:提前
<form name='profileForm' >
<div class="section">
<label class="title">Name <span class="help">(required)</span>
<textarea ng-model="createdProfile.name" ></textarea>
</label>
</div>
<div class="section">
<button class="btn btn-large highlight" ng-disabled="!profileForm.$valid" ng-click="addProfile()">Save</button>
</div>
</form>
感謝您的幫助:
<h1>{{user.name}}</h1>
{{user.location}}
...
功能addProfile從一個按鈕叫表單中,像這樣!
沒有看到您的控制器代碼,很難說出什麼問題可能。但是,不是'$ scope.user = savedUser;',而是嘗試'angular.copy(savedUser,$ scope.user)'。 – 2013-05-13 14:04:40
感謝您的建議。我試了一下,但沒有改變。我在描述中添加了更多的上下文。讓我知道這是否有幫助? – Dine 2013-05-13 14:25:51
它可能是一個範圍問題(即更新錯誤的$範圍)。嘗試添加'console.debug($ scope)'到您的保存回調中,並將'{{$ id}}'添加到您的視圖中。確保你看到兩個相同的作用域ID。 – 2013-05-13 14:34:49