<app-component [date]="'13.10.2022'">
<app-test-content [content]="content"></app-test-content>
</app-component >
Here is from app-component
<div *ngFor="let number of [1,2,3]">
<h1>{{date}}</h1>
<ng-content></ng-content>
</div>
如何将日期放在每个ng-内容之后?
目前是这样的:
13.10.2022
13.10.2022
13.10.2022
标题
是一种很好的方法。[医]月桂,[医]雷公藤,[医]罗汉果。
标题2
是一种很好的方法。[医]月桂,[医]雷公藤,[医]罗汉果2。
标题3
是一种很好的方法。[医][[ est ]][[est]][[est]]( rhoncus3 )
但我需要:
13.10.2022
标题‘.’‘.’‘.’.‘’.‘’[医]月桂,[医]雷公藤,[医]罗汉果。
13.10.2022
标题2‘.’‘.[医]月桂,[医]雷公藤,[医]罗汉果2。
13.10.2022
标题3‘.’‘.’.[医][医]毛霉[ est ]][[est],rhoncus3.
发布于 2022-10-13 11:28:08
为了在循环中进行角内容投影,要在循环内进行角内容投影,需要使用ngTemplateOutlet
而不是ng内容。
ngTemplateOutlet指令允许您从TemplateRef创建嵌入式视图。TemplateRef表示可用于实例化嵌入视图的嵌入模板。
在父组件中:
<app-child [date]="'13.10.2022'">
<ng-template #textSlot let-text>
{{content}}
</ng-template>
</app-child>
在儿童部分:
<div>
<div *ngFor="let number of [1,2,3]">
<h1>{{date}}</h1>
<div>
<ng-container
*ngTemplateOutlet="textSlotTmpl,
context: { $implicit: text }"
></ng-container>
</div>
</div>
</div>
child.component.ts:
import { Component, Input, ContentChild, TemplateRef } from "@angular/core";
@Component({
selector: "app-child",
templateUrl: "./child.component.html",
styleUrls: ["./child.component.css"]
})
export class ChildComponent {
@Input() date: string;
@ContentChild("textSlot") textSlotTmpl: TemplateRef<any>;
}
然后你就会得到你的预期结果。
https://stackoverflow.com/questions/74054214
复制相似问题