import { Component } from '@angular/core';
let instances = 0;
@Component({
selector: 'counter',
template: '<h1>{{this.id}}</h1>'
})
class Counter {
id: number;
constructor() {
this.id = ++instances;
}
}
import { Component } from '@angular/core';
@Component({
selector: 'wrapper',
template: `
<div class="box">
<ng-content></ng-content>
</div>
`
})
class Wrapper {}
<wrapper> <counter></counter> <counter></counter> <counter></counter> </wrapper>
import { Component } from '@angular/core';
@Component({
selector: 'wrapper',
template: `
<div class="box red">
<ng-content></ng-content>
</div>
<div class="box blue">
<ng-content select="counter"></ng-content>
</div>
`,
styles: [`
.red {background: red;}
.blue {background: blue;}
`]
})
export class Wrapper { }
<wrapper> <span>This is not a counter</span> <counter></counter> </wrapper>
<wrapper> <ng-container> <counter></counter> </ng-container> </wrapper>
<wrapper> <ng-container ngProjectAs="counter"> <counter></counter> </ng-container> </wrapper>
<div class="box red"> <ng-content></ng-content> </div> <div class="box blue"> <ng-content></ng-content> </div>
import { Component } from '@angular/core';
@Component({
selector: 'wrapper',
template: `
<button (click)="show = !show">
{{ show ? 'Hide' : 'Show' }}
</button>
<div class="box" *ngIf="show">
<ng-content></ng-content>
</div>
`
})
class Wrapper {
show = true;
}
import { Component } from '@angular/core';
@Component({
selector: 'wrapper',
template: `
<div class="box" *ngFor="let item of items">
<ng-content></ng-content>
</div>
`
})
class Wrapper {
items = [0, 0, 0];
}
<div class="my-wrapper"> <counter></counter> </div>
<third-party-wrapper> <counter></counter> </third-party-wrapper>
<wrapper> <ng-template> <counter></counter> </ng-template> </wrapper>
@Component({
selector: 'wrapper',
template: `
<button (click)="show = !show">
{{ show ? 'Hide' : 'Show' }}
</button>
<div class="box" *ngIf="show">
<ng-container [ngTemplateOutlet]="template"></ng-container>
</div>
`
})
class Wrapper {
show = true;
@ContentChild(TemplateRef) template: TemplateRef;
}
@Component({
selector: 'wrapper',
template: `
<div class="box" *ngFor="let item of items">
<ng-container [ngTemplateOutlet]="template"></ng-container>
</div>
`
})
class Wrapper {
items = [0, 0, 0];
@ContentChild(TemplateRef) template: TemplateRef;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有