1
我工作的一對應該當用戶點擊一個按鈕,從假的值更改爲true角度的功能。該應用跟蹤用戶喜歡的書籍;當用戶創建收藏夾時,「跟蹤」和「完成」的默認值設置爲false。當用戶去使用它們升級到真正的NG-點擊,新的「真」值未打補丁的數據庫,並在控制檯登錄爲靜止假。對我的功能缺少什麼想法?角功能不更新數據庫
$scope.trackFavorite = function(favorite) {
var favoriteParams = {
id: favorite.id,
tracking: favorite.tracking,
finished: favorite.finished
};
favorite.tracking = !favorite.tracking;
$http.patch("/api/v1/favorites/"+favorite.id+".json", favoriteParams).success(function(response) {
console.log("READING NOW");
console.log(response);
});
};
$scope.markFinished = function(favorite) {
var favoriteParams2 = {
id: favorite.id,
finished: favorite.finished,
};
favorite.finished = !favorite.finished;
console.log(favorite);
$http.patch("/api/v1/favorites/"+favorite.id+".json", favoriteParams2).success(function(response){
console.log("IS IT FINISHED");
console.log(response);
});
};
下面是從視圖中的NG-點擊片段,以防萬一:
<div>
<button ng-class="{tracking: favorite.tracking}" ng-click="trackFavorite(favorite)">Reading Now</button>
</div>
<div>
<button ng-class="{finished: favorite.finished}" ng-click="markFinished(favorite)">Finished</button>
</div>
非常感謝!
你應該看看從你的承諾回來的錯誤,這將給你的背景,爲什麼它沒有正確保存。 – Makoto