We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ngIf可以对元素进行显示和隐藏,它和javascript中使用方法差不多
if(isFruit){ }else{ }
isFruit是一个布尔类型的变量: isFruit = true;
isFruit
*ngIf
<div *ngIf="isFruit; then otherFruit; else animal"> 苹果 </div>
*ngIf,then
<div *ngIf="isFruit; then otherFruit"> 苹果 </div> <ng-template #otherFruit> <div> 香蕉 </div> </ng-template>
otherFruit是模板名称,可以自定义任何名称。它的作用是让ngIf里面的代码可以抽离出来。
otherFruit
ngIf
*ngIf,then,else
<div *ngIf="isFruit; then otherFruit; else animal"> 苹果 </div> <ng-template #otherFruit> <div> 香蕉 </div> </ng-template> <ng-template #animal> <div> 狸花猫 </div> </ng-template>
在ngIf中如何使用正则表达式?可以把要做的判断提取到js里面判断。
<ul *ngFor="let data of testStrings"> <li *ngIf="judge(data)"> {{ data }} </li> </ul>
testStrings = ["javascript", "jav", "avaj", "nodejs"]; judge(data){ return /java/.test(data) }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
ngIf可以对元素进行显示和隐藏,它和javascript中使用方法差不多
1.
*ngIf
表示值为true时显示,false时隐藏2.
*ngIf,then
表示值为true时两个都显示,false时隐藏otherFruit
是模板名称,可以自定义任何名称。它的作用是让ngIf
里面的代码可以抽离出来。3
*ngIf,then,else
表示值为true时ngIf和then两个里的都显示,else里的内容隐藏ngIf里面使用正则表达式
在
ngIf
中如何使用正则表达式?可以把要做的判断提取到js里面判断。The text was updated successfully, but these errors were encountered: