1

angular-ui 유형 권장 및 ng-switch를 사용하고 있습니다. 목표는 사전 입력 상자가 입력 된 경우 "개인 정보"로 시작하는 행이 나타납니다. 그렇지 않으면 나타나지 않습니다. 이제 문제는이 행이 항상 나타납니다.ng-switch는 angular-ui 유형에 대해 작동하지 않습니다.

여기에 플 런커를 만들었습니다. http://plnkr.co/edit/qEaYE6BHjmMewmlheFoh

해당 코드 세그먼트는 다음과 같습니다. HTML;

<div class='container-fluid' ng-controller="TypeaheadCtrl"> 
     <h4>Static arrays</h4> 
     <!-- <pre>Model: {{selected }}</pre> 
     <pre>Model: {{selected.name}} {{selected.id}}</pre> --> 
     <div ng-switch="selected.name"> 
      <div ng-switch-when="" > 
       <BR><BR>     
      </div> 
      <div ng-switch-default >    
       <pre>Person info: {{selected.name}} {{selected.id}}</pre> 
      </div> 
     </div> 

     <input type="text" ng-model="selected" 
       typeahead="person as person.name for person in person_info | filter:{name:$viewValue} | limitTo:8"     
       class="form-control">   
    </div> 

자바 스크립트 컨트롤러 :

var person_info = [ 
         { 
           "name": "Tom", 
           "id": "111" 
         }, 
         { 
           "name": "Sam", 
           "id": "222" 
         }, 
         { 
           "name": "James", 
           "id": "333" 
         } 
        ]; 
    $scope.person_info = person_info; 

답변

2

대신 NG 스위치의 당신은/NG 쇼/NG 숨기기 여기

는 NG-경우

와 코드 NG-경우 사용할 수 있습니다
<div ng-if="selected.name == null" > 
     <BR><BR>     
</div> 
<div ng-if="selected.name">    
     <pre>Person info: {{selected.name}} {{selected.id}}</pre> 
</div> 

그냥 ng-switch로 바꿉니다.