how to check for null with a ng-if values in a vie

2019-03-22 19:06发布

i have this situation

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

but test.view== null doesn't work, neither just checking for test.view or test.view == ''

any ideas?

thanks

edit:

in the loop, sometimes test.view, has a value sometimes is NULL if i do:

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

i will only see 1

4条回答
Animai°情兽
2楼-- · 2019-03-22 19:21

As per documentation

<div *ngIf="entity.category; then ifCategory; else ifNoCategory">this is ignored</div>
<ng-template #ifCategory>{{entity.category.name}}</ng-template>
<ng-template #ifNoCategory>No category found</ng-template>
查看更多
欢心
3楼-- · 2019-03-22 19:30

See the correct way with your example:

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

Regards, Nicholls

查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-03-22 19:33

You should check for !test, here is a fiddle showing that.

查看更多
再贱就再见
5楼-- · 2019-03-22 19:38

You can also use ng-template, I think that would be more efficient while run time :)

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

Cheers

查看更多
登录 后发表回答