Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 离子、角度、显示或禁用控制器内的组件_Angularjs_Components_Hide_Ionic - Fatal编程技术网

Angularjs 离子、角度、显示或禁用控制器内的组件

Angularjs 离子、角度、显示或禁用控制器内的组件,angularjs,components,hide,ionic,Angularjs,Components,Hide,Ionic,我有以下代码。以下代码显示5个标记项。 我想做的是,当用户单击任何标记项时,它将被隐藏或清空。但当我点击其中任何一个时,所有的标签项都被抹掉了,而不是我选择的项目。谁能给我一些建议吗 <div data-ng-repeat="x in mylist"> <a class="button" ng-click="hideme();" style="{{visibility}}">{{x}}</a> </div> .controller('

我有以下代码。以下代码显示5个标记项。 我想做的是,当用户单击任何标记项时,它将被隐藏或清空。但当我点击其中任何一个时,所有的标签项都被抹掉了,而不是我选择的项目。谁能给我一些建议吗

<div data-ng-repeat="x in mylist">
   <a class="button" ng-click="hideme();" style="{{visibility}}">{{x}}</a> 
</div>  

.controller('MyCtrl', function($scope, $stateParams, chats) {      
    $scope.hideme = function(index, value) {
        $scope.visibility = "background-color: #000000 !important;";
    }
}); 

{{x}
.controller('MyCtrl',函数($scope,$stateparms,chats){
$scope.hideme=函数(索引,值){
$scope.visibility=“背景色:#000000!重要;”;
}
}); 

首先,您可能需要稍微更改对象结构。请记住,在模型值中始终有一个点(.)

试试这个

<div ng-app ng-controller="myCtrl">
    <div ng-repeat="x in myList">
        <a href="" ng-click="hide(x)" ng-hide="x.hide">{{x.value}}</a>
    </div>
</div>

function myCtrl($scope){
    $scope.myList = [{
        value: "a"
    }, {
        value: "b"
    }, {
        value: "c"
    }];

    $scope.hide = function(obj){
        obj.hide = true;
    }

}

函数myCtrl($scope){
$scope.myList=[{
价值:“a”
}, {
值:“b”
}, {
值:“c”
}];
$scope.hide=函数(obj){
obj.hide=true;
}
}

Hi Askash,您的代码可以正常工作。但我不太明白为什么我不能这样做<代码>函数myCtrl($scope){
$scope.myList=[{value:[“a”、“b”、“c”]}];
$scope.hide=function(obj){
obj.hide=true;
}
原因是,如果检查“a”、“b”和“c”,您将看到angular为每次重复添加了一个类调用ng scope。这意味着范围内的任何更改将仅应用于该模型。但是,如果您直接将其添加到$scope对象中,那么所有模型的行为都将改变。您可能想了解angularjs中的作用域是如何工作的。