Requirement: A list generated using the ng-repeat command is displayed on the page. When you click an item, it is hidden. Q: How can I operate the ng-show value of the current item in the ng-click callback without affecting other items? Code: {code...} requirement: the page has a usage
ng-repeatThe list generated by the command. When you click an item, it is hidden.
Question: How can Ing-clickTo operate the current itemng-showDoes not affect other items?
Code:
《script》 var myApp = angular.module('myApp',[]); myApp.controller('listCtrl',function($scope){ var items = [{title:"title1",price:120},{title:"title2",price:23},{title:"title3",price:32234}] $scope.items = items; // $scope.show = "true"; $scope.delete = function(item){ // $scope.show = "false" } })《script》
Reply content:
Requirement: the page has a usageng-repeatThe list generated by the command. When you click an item, it is hidden.
Question: How can Ing-clickTo operate the current itemng-showDoes not affect other items?
Code:
《script》 var myApp = angular.module('myApp',[]); myApp.controller('listCtrl',function($scope){ var items = [{title:"title1",price:120},{title:"title2",price:23},{title:"title3",price:32234}] $scope.items = items; // $scope.show = "true"; $scope.delete = function(item){ // $scope.show = "false" } })《script》
《script》 var myApp = angular.module('myApp',[]); myApp.controller('listCtrl',function($scope){ var items = [{title:"title1",price:120},{title:"title2",price:23},{title:"title3",price:32234}] $scope.items = items; // $scope.show = "true"; $scope.delete = function(item){ $scope.item.show = "false" } })《script》
Set a hidden attribute, combined with the list$indexYou can.
angular.module('myApp',[]) .controller('listCtrl',function($scope){ var items = [{title:"title1",price:120},{title:"title2",price:23},{title:"title3",price:32234}] $scope.items = items; $scope.hidden = {value: null} // $scope.show = "true"; $scope.change = function(i) { $scope.hidden.value = i; } })
The reason for setting hidden as an object rather than the original value is thatng-repeatHas an independent scope, directly inng-repeatModifying the original value in the scope of parent controller does not change. You need to use the reference type, such as an object or array to ensure that the modification is saved to the parent controller.
Http://jsbin.com/modute/edit? Html, js, output
@ Onelove: