typescript ngif-then.component.ts
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了typescript ngif-then.component.ts相关的知识,希望对你有一定的参考价值。
@Component({
selector: 'ng-if-then',
template: `
<button (click)="switchPrimary()">Switch Template</button>
<div *ngIf="show; then thenBlock"></div>
<ng-template #primaryBlock>Primary</ng-template>
<ng-template #secondaryBlock>Secondary</ng-template>
`
})
class NgIfThenElse implements OnInit {
thenBlock: TemplateRef<any> = null;
show: boolean = true;
@ViewChild('primaryBlock')
primaryBlock: TemplateRef<any> = null;
@ViewChild('secondaryBlock')
secondaryBlock: TemplateRef<any> = null;
switchPrimary() {
this.thenBlock = this.thenBlock === this.primaryBlock ? this.secondaryBlock : this.primaryBlock;
}
ngOnInit() { this.thenBlock = this.primaryBlock; }
}
以上是关于typescript ngif-then.component.ts的主要内容,如果未能解决你的问题,请参考以下文章
TypeScript入门五:TypeScript的接口
TypeScript系列教程--初探TypeScript
TypeScript入门三:TypeScript函数类型
typescript使用 TypeScript 开发 Vue 组件
认识 TypeScript
Learining TypeScript TypeScript 简介