我试图在我的 ionic 移动应用程序上按下“赞”按钮后隐藏它。但它不是只隐藏该按钮,而是隐藏所有类似的按钮。如何单独隐藏 1 个按钮而不是隐藏所有按钮?这是我尝试实现的代码。
事件.html:
<div class="item item-text-wrap" ng-repeat="activities1 in activities" id = $index>
<div>
Seen on: {{activities1.viewedDate}}
<br>
{{activities1.title}}
</div>
<iframe width="420" height="315" src="{{activities1.url}}"></iframe>
<div class="item item-input-inset">
<button class="button button-full button-balanced" ng-click="invertLike(activities1);" ng-hide="ShowDiv">
Like!
</button>
<button class="button button-full button-assertive" ng-click="Dislike(activities1);" ng-hide="ShowDiv2">
Unlike!
</button>
</div>
</div>
Controller .js:
database.ref('/activitiesInvite/' ).orderByChild("name").equalTo(username).on('value', function(activitys){
$scope.activities = activitys.val();
$scope.invertLike = function(index) {
var id = index.id;
firebase.database().ref('activitiesInvite').orderByChild("id").equalTo(id).on("value", function(snapshot)
{
{
var key;
$scope.check = snapshot.val().interest;
console.log($scope.check);
snapshot.forEach(function (childSnapshot) {
key = childSnapshot.key;
})
if(key)
{
firebase.database().ref('/activitiesInvite/' + key).on("value", function(test)
{
firebase.database().ref().child('/activitiesInvite/' + key)
.update({ interest: "user has liked", });
if($scope.check != "")
{
$scope.ShowDiv = true;
}
})
}
}
任何帮助将不胜感激。
最佳答案
由于按钮共享模型数据,可能会出现此问题。您可以添加一个子 Controller 并将按钮包裹在其周围。那会解决你的问题。请参阅完整的示例代码:https://plnkr.co/edit/eVgedv9WFGmKewcI7j6C?p=preview
//Main Module, Main Controller
angular.module('myApp', []).controller('MainCtrl', function($scope) {
$scope.activities = [{
title: 'Jani',
url: 'www.google.com',
viewedDate: new Date().toLocaleDateString("en-US")
}];
$scope.ShowDiv = false;
$scope.ShowDiv2 = false;
})
//Child Controller (Isolate the Scope of the variables from Parent Controller)
.controller('ChildCtrl', function($scope) {
$scope.invertLike = function(activities1) {
//Scope Inherited From Parent
$scope.ShowDiv = true;
};
$scope.Dislike = function(activities1) {
//Scope Inherited From Parent
$scope.ShowDiv2 = true;
};
});
关于javascript - Ionic 1 - 按下按钮后隐藏按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42184509/