美文网首页
ngIf then else

ngIf then else

作者: 4f4e62418dff | 来源:发表于2018-08-31 11:13 被阅读0次

ngIf then else 语句。

.......
<ng-container *ngIf="value;then thenBlock;else elseBlock"></ng-container>
........
<ng-template #thenBlock>.....</ng-template>
<ng-template #elseBlock>......</ng-template>

不过这个语句有个缺点,就是没有办法很好的结合context语法传递参数。
如果你的value就包含了你需要在thenBlock中要显示的所有信息,且elseBlock只展示固定的字符串的时候才可以使用。
eg:

.......
<ng-container *ngIf="object;then thenBlock;else elseBlock"></ng-container>
.......
<ng-template #thenBlock let-object>{{object.value1}}{{object.value2}}</ng-template>
<ng-template #elseBlock>...some string...</ng-template>

或者直接将thenBlock写在里面:

.......
<ng-container *ngIf="object;else elseBlock">
  <div>{{object.value1}}{{object.value2}} 该怎么写就怎么写...</div>
</ng-container>
.......

<ng-template #elseBlock>...some string...</ng-template>

相关文章

网友评论

      本文标题:ngIf then else

      本文链接:https://www.haomeiwen.com/subject/utkswftx.html