我使用角度4,我想在这个例子中使用ngIf else:
<div *ngIf="isValid"> content here ... </div> <div *ngIf="!isValid"> other content here... </div>
如何用其他方式实现相同的行为?
角4.0.0决赛:
原文链接:https://www.f2er.com/angularjs/142773.html使用其他:
<div *ngIf="isValid;else other_content"> content here ... </div> <ng-template #other_content>other content here...</ng-template>
你也可以使用其他的:
<div *ngIf="isValid;then content else other_content">here is ignored</div> <ng-template #content>content here...</ng-template> <ng-template #other_content>other content here...</ng-template>
或者一个人:
<div *ngIf="isValid;then content"></div> <ng-template #content>content here...</ng-template>
演示:
细节:
<纳克模板> :是Angular自己实现的< template>标签根据MDN:
The HTML
<template>
element is a mechanism for holding client-side content that is not to be rendered when a page is loaded but may subsequently be instantiated during runtime using JavaScript.