Javascript-AngularJS operation ng-show command

Source: Internet
Author: User
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.

  
  
  • {{item.title}}
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:


  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.