Answer the question
In order to leave comments, you need to log in
How to pass value to ng-content Angular8?
There is such an Angular 8 component:
// a.component.ts
@Component({
selector: 'app-a'
templateUrl: './a.component.html',
})
class AComponent {
@Input() text: string;
}
// a.component.html
<ng-content></ng-content>
// b.component.ts
@Component({
selector: 'app-b'
templateUrl: './b.component.html',
})
class BComponent{
@Input() text: string = "none";
}
// b.component.html
<div>
text: {{ text }}
</div>
// app.component.html
<app-a text="ABCDE">
<app-b text="ABCDE"></app-b>
<app-b text="ABCDE"></app-b>
<app-b text="ABCDE"></app-b>
</app-a>
// app.component.html
<app-a text="ABCDE">
<app-b></app-b>
<app-b></app-b>
<app-b></app-b>
</app-a>
Answer the question
In order to leave comments, you need to log in
At the app-a level, in providers, write a service that will receive data for further distribution, in the same component, write data from @Input to the service.
Inject the created service into app-b and take data from it
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question