想請問一下如果我目前有兩個Component
父Component有一個 可以嵌入子Component的內容
如果我想要用多個 加上 select 來做多個嵌入 是否可行呢
目前 是可以嵌入內容的,可是加上 就會無法
不知是我寫錯還是不能這樣用
Parent
import { Component, OnInit, ContentChild } from "@angular/core";
import { ChildComponent } from "../child/child.component";
@Component({
selector: "app-parent",
templateUrl: "./parent.component.html",
template: `
<p *ngIf="childCmp">
{{childCmp.name}}
</p>
<ng-content select='.body'></ng-content>
`,
styleUrls: ["./parent.component.css"]
})
export class ParentComponent {
@ContentChild("target") childCmp: ChildComponent;
ngAfterContentInit() {
console.dir(this.childCmp);
}
}
ChildComponent
import { Component, OnInit } from "@angular/core";
@Component({
selector: "app-child",
template: `
<p class='body'>
child body!
</p>
<p class='foot'>
child foot!
</p>
`,
styleUrls: ["./child.component.css"]
})
export class ChildComponent {
public name: string = "get child name";
}