私はウィッシュリストを実装しています。新しいデータを表示するためにページをリフレッシュせずにウィッシュリストからコンテンツを削除したいと思います。ここで は私がやったことです:あなたは、私が$window.location.reload();
しようとしたコメントの中で見ることができますが、ページ全体ではなく一つの項目を削除すると、再びアップロードされているので、それはさわやかようなものだとしてページをリフレッシュまたはロードせずに角度のデータを更新する
wish.controller('wishCtrl',['$scope','$http','$cookies','$window',function($scope,$http,$cookies,$window) {
var user={};
user.email = $cookies.get('cookieEmail');
$http.get("http://localhost:3000/wishlist/"+user.email).success(function(data){
$scope.wishController = data;
console.log(data);
});
var delclick=0;
var newView =0;
$scope.delClick = function(title, des, subj) {
var wish = {};
wish.user = $cookies.get('cookieEmail');
wish.sub = subj;
wish.title = title;
wish.description=des;
console.log(wish.user);
console.log(wish.title);
console.log(wish.sub);
console.log(wish.description);
delclick=1;
if(delclick==1)
{
$http.post('http://localhost:3000/wishlistDel', wish).then()
//$scope.load();
//$window.location.reload();
}
}
}]);
からdisplay:none
のように、行うにはどのような方法がありますそれ?
編集
<div ng-repeat="wishlist in wishController.Themes" >
<h2 class="text-center">{{wishlist.title}}</h2>
<h2 class="text-center">{{wishlist.description}}</h2>
<img ng-src="{{wishlist.image}}" class="imgCenter">
<button class="w3-btn w3-ripple" ng-click="delClick(wishlist.title, wishlist.description, wishlist.sub, $index)">click </button>
</div>
更新
$http.post('http://localhost:3000/wishlistDel', wish).then(function() {
if(item.sub=='party'){
var index = $scope.wishController.Party.indexOf(item);
console.log(index);
if(index !== -1){
$scope.wishController.Party.splice(index,1);
}
}
if(item.sub=='activity'){
var index = $scope.wishController.Activity.indexOf(item);
console.log(index);
if(index !== -1){
$scope.wishController.Activity.splice(index,1);
}
}
if(item.sub=='theme'){
var index = $scope.wishController.Themes.indexOf(item);
console.log(index);
if(index !== -1){
$scope.wishController.Themes.splice(index,1);
}
}
});
}
確認の目的は何ですかビュー – charlietfl
からあなたの元のオブジェクトに渡すことで、これを簡素化することができます'delclick = 1;'を設定し、すぐに 'if(delclick == 1)'をテストしますか? – Lex
ng-clickでは$ indexを追加しますが、関数内では追加しません。 – rneves