私は独自のカートシステムを角度とノードで構築しようとしています。私のコントローラーは、mongoデータベースのユーザーカートとローカルストレージのカート(ユーザーがアカウントを持っていない場合)の両方を処理します。今、カートのコントローラがローカルストレージとデータベースの両方からカートアイテムを削除する方法を作成しました。私のアングルビューはオブジェクトを見ます。角度範囲変数の変更を監視する方法
$scope.lineItems
カートに商品を入れるため。今すぐカートを更新することができますが、ページを更新する必要があります。スコープを更新する関数をトリガしてスコープを更新するにはどうすればよいでしょうか?
コード:
if (token) {
var payload = authService.parseToken(token);
dataService.getCart(payload._id).then(function (resolve){
if (resolve.data){
$scope.lineItems = resolve.data;
$scope.deleteLineItem = function(lineitem){
dataService.deleteLineItem([lineitem.lineItemID, payload._id]);
}
}
}, function(reason){
console.log(reason);
});
} else {
if (dataService.retrieveLocal('localCart')){
$scope.lineItems = dataService.retrieveLocal('localCart');
$scope.deleteLineItem = function(lineitem){
var cart = dataService.retrieveLocal('localCart');
var updatedCart = cart.filter(function(item){
if (lineitem.lineItemID != item.lineItemID){
return item
}
})
dataService.storeToLocal('localCart', updatedCart);
}
}
}