angular的if else; ng if else

 时间:2026-02-12 20:49:32

1、打开新创建好的angualr项目,找到app.component.ts文件,定义一个变量为bool,默认设置值为false。如图所示

angular的if else; ng if else

2、打开app.component.html文件,添加angular提供的if else 写法。 如图所示

代码:

<ng-container *ngIf="bool; else elseTemplate">

    bool为true显示

  </ng-container>

  <ng-template #elseTemplate>

    bool为false显示

  </ng-template>

angular的if else; ng if else

3、保存代码后启动项目,然后在浏览器上打开,即可看到浏览器上显示bool为fasle的语法提示,修改app.component.ts文件里面的bool值即可看到另外一个提示。

angular的if else; ng if else

  • npm代理如何设置npm网络链接失败如何设置
  • linux如何删除文件
  • jQuery如何获取textarea文本域的值?
  • css如何设置默认宽度,然后由内容来自动增加宽度
  • javascript(js)中怎么获取父元素的值?
  • 热门搜索
    福鼎旅游 马鞍山旅游汽车站 惠州奥地利小镇旅游 上海旅游介绍 十一去哪旅游好 阳西沙扒湾旅游攻略 漯河旅游景点大全 河南省旅游网 南京旅游景点地图 洛带古镇旅游攻略