2015-01-11 2 views
1

표시/숨김 DOM에 ng-model을 추가 한 다음 ng-show = "thatElement.visiblity === 'true'"?다른 DOM이 보이는 경우 어떻게 항목을 표시합니까?

<span>Show this text when the div is visible</span> 
<div ng-repeat="user in users" ng-show="user.section===radio.model">{{user.name}}</div> 

업데이트 : 사업부가 보일 때 내가보기이 텍스트를 넣을 경우, 사용자의 모든 사용자에 대해 반복 할 것입니다. (가 명확하지 이후)이 사업부는 모든 시간을 표시 할,하고 조건이 충족되는 경우에만 걸쳐있는 경우, 당신을

<div ng-repeat="user in users" ng-show="user.section===radio.model"> 
    <span>Show this text when the div is visible</span> 
    <div>{{user.name}}</div> 
</div> 

또는 :

답변

1

당신은 그것을 재구성 할 필요가 이 작업을 수행 할 수 있습니다

<div ng-repeat="user in users"> 
    <span ng-show="user.section===radio.model">Show this text when the div is visible</span> 
    <div>{{user.name}}</div> 
</div> 

당신은 또한 당신이 그런 불필요한 하위 객체 처리를 피할 수 있도록 NG-반복 입력 객체를 분류하는 필터를 사용할 수 있습니다. 하나의 범위를 표시할지 여부를 나타 내기 위해 부울을 사용

angular.module('app', []) 
 
    .controller('ctrl', function($scope) { 
 
    $scope.users = [{ 
 
     name: 'Mr. Visible', 
 
     visibility: true 
 
    }, { 
 
     name: 'Mr. Invisible', 
 
     visibility: false 
 
    }] 
 
    })
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div ng-app="app" ng-controller="ctrl"> 
 
    <div ng-repeat="user in users"> 
 
    <span ng-if="user.visibility">Show this text when the div is visible</span> 
 
    <div>{{user.name}}</div> 
 
    <br /> 
 
    </div> 
 
</div>


UPDATE

예 : 여기


는 스팬에 ng-if를 이용한 간단한 예제 :

angular.module('app', []) 
 
    .controller('ctrl', function($scope) { 
 
    $scope.users = [{ 
 
     name: 'Mr. Visible', 
 
     visibility: true 
 
    }, { 
 
     name: 'Mr. Invisible', 
 
     visibility: false 
 
    }]; 
 

 
    $scope.showSpan = false; 
 
    for (var i in $scope.users) { 
 
     if ($scope.users[i].visibility) { 
 
     $scope.showSpan = true; 
 
     break; 
 
     } 
 
    } 
 
    })
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div ng-app="app" ng-controller="ctrl"> 
 
    <span ng-show="showSpan">Show this text when the div is visible</span> 
 
    <div ng-repeat="user in users"> 
 
    <div>{{user.name}}</div> 
 
    <br /> 
 
    </div> 
 
</div>

+1

당신은 환영합니다! 괜찮습니다. 두 번째 예제가 효과가 있습니다. 스팬을 숨기는 대신 완전히 제거하고 싶다면'ng-if'를 사용할 수 있습니다. 물론 외부 요소에 대해이 작업을 수행 할 수 있지만 추가 모델과 관찰자가 필요합니다. ** 실제로 ** 필요한 경우가 아니면 권장하지 않습니다. – Shomz

+1

Div에는 ng 모델이 없습니다. 입력 요소 (input, select, textarea ...) 만 수행합니다. 여기를 참조하십시오 : https://docs.angularjs.org/api/ng/directive/ngModel 무엇을하고 싶습니까? – Shomz

+1

내 예제를 조사하지 않을거야. 가시성을 가진 사람들을위한 것입니다. – Shomz

관련 문제