programing

angularjs가 있는 뷰에서 ng-if 값을 사용하여 null을 확인하는 방법

jooyons 2023. 4. 5. 21:32
반응형

angularjs가 있는 뷰에서 ng-if 값을 사용하여 null을 확인하는 방법

나는 이런 상황이 있다.

<div ng-repeat="test in current">
    <div ng-if="test.view == null">
        <i class="icon ion-checkmark"></i>
    </div>
</div>

그렇지만test.view== null동작하지 않습니다.또한 확인만 할 수도 없습니다.test.view또는test.view == ''

좋은 생각 있어?

감사해요.

편집:

때로는 루프에서test.view다음과 같은 경우 값은 NULL이 될 수 있습니다.

<div ng-if="!test.view">1</div>
<div ng-if="test.view">2</div>

나는 오직 볼 것이다1

다음을 확인해야 합니다.!test여기 그것을 보여주는 바이올린이 있다.

<span ng-if="!test">null</span>

올바른 예제를 참조해 주세요.

<div ng-if="!test.view">1</div>
<div ng-if="!!test.view">2</div>

경구, 니콜스

ng-template도 사용할 수 있습니다.실행시간에는 효율이 높다고 생각합니다.

<div ng-if="!test.view; else somethingElse">1</div>
<ng-template #somethingElse>
    <div>2</div>
</ng-template>

건배.

여기 내가 설명하려고 했던 간단한 예가 있다.

<div>
    <div *ngIf="product">     <!--If "product" exists-->
      <h2>Product Details</h2><hr>
      <h4>Name: {{ product.name }}</h4>
      <h5>Price: {{ product.price | currency }}</h5>
      <p> Description: {{ product.description }}</p>
    </div>

    <div *ngIf="!product">     <!--If "product" not exists-->
       *Product not found
    </div>
</div>

언급URL : https://stackoverflow.com/questions/23556092/how-to-check-for-null-with-a-ng-if-values-in-a-view-with-angularjs

반응형