2016-12-01 2 views
0
<!DOCTYPE html> 
<html> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 
<body> 

<div ng-app="myApp" ng-controller="myCtrl"> 
<div ng-repeat='x in trail'> 
<input type=checkbox ng-model='one1'>{{x}}</div> 
<div ng-repeat='x in array'> 
<p ng-hide='one1' >{{x}}</p> 
</div> 
</div> 
</div> 

<script> 
var app = angular.module('myApp', []); 
app.controller('myCtrl', function($scope) { 
$scope.trail = ["Volvo","bike","access","rocket"]; 
$scope.array = ["Volvo","bike","access","rocket"]; 
}); 
</script> 
</body> 
</html> 

이 코드를 실행하고 확인란을 클릭하면 전체 배열 값이 숨겨 지지만 숨겨지지 않습니다.NG 모델이 제대로 업데이트되지 않습니다.

+0

당신은 $ scope.one1 = 거짓을 작성할 수 있습니다; 귀하의 컨트롤러에? – hurricane

+0

예,하지만 checkboxc를 사용하여 one1의 값을 설정하고 싶습니다. – Abhishek

+0

이걸 가지고 있는데 사용하기 전에 초기화해야합니다. – hurricane

답변

0

당신이 정말로 전체 배열을 숨기려면

<input type=checkbox ng-model="x.checked"> 

당신은 demo here

0

을 볼 수 있습니다 "확인"와 같은 scope.trail 배열 뭔가를 $에 변수를 추가, 당신은 ng-change 지시 전달을 활용할 수 있습니다 그것은

here is a demo

0

에 대한 모델은 사실 나는 당신의 exampl에 문제가 발견 이자형. ng-repeat를 만들고 동일한 범위 값을 사용하는 입력 영역을 사용하는 경우 배열 값은 범위 값과 동일하지 않습니다.

var myApp = angular.module('myApp',[]); 

function MyCtrl($scope) { 
    $scope.trail = ["Volvo","bike","access","rocket"]; 
     $scope.array = ["Volvo","bike","access","rocket"]; 
    $scope.one = true; 
} 

<div ng-app="myApp" ng-controller="MyCtrl"> 
<input type="checkbox" ng-model="one">{{one}} {{x}} 
    <div ng-repeat='x in trail'> 

    </div> 
    <div ng-repeat='x in array'> 
    <label ng-show="one == true" >{{x}}</label> 
    </div> 
</div> 

Working Example

관련 문제