在我的离子移动应用程序上按下按钮后,我试图隐藏它。但它不是只隐藏那个按钮,而是隐藏所有类似的按钮。如何单独隐藏1个按钮而不是隐藏所有内容?这是我试图实现的代码。
activities.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;
}
})
}
}
非常感谢任何帮助。
答案 0 :(得分:1)
问题可能正在发生,因为按钮已共享模型数据。您可以添加子控制器并包围它周围的按钮。这将解决您的问题。请参阅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;
};
});