In my Angular 7 app I have a simple home component using one-way data binding on a string variable (i.e. I pass a variable to a child component using @Input with the [text]="'Some text'" syntax).
I would like to include html tags such as links in the variable and render it in the child component but the code below fails because of the anchor tag. How to fix this?
home.component.ts:
{ Component } from '@angular/core';
@Component({
selector: 'app-home',
template: '
<app-card [text]="'Some text and a link: <a href="https://stackoverflow.com" target="_blank">link</a>'">
</app-card>
',
styleUrls: ['./home.component.css']
})
export class HomeComponent {}
card.component.ts:
import { Component, Input } from '@angular/core';
@Component({
selector: 'app-card',
template: '
<div class="bla bla">
<p>{{text}}</p>
</div>
',
styleUrls: ['./card.component.css']
})
export class CardComponent {
@Input() text: string;
}
Edit: I wrote 'templateUrl' but that was wrong, I mean 'template'. Let me add that my real card template is more complicated than the div shown here, and I actually use templateUrl in both components as follows:
templateUrl: './about.component.html', //in app component
templateUrl: './card.component.html', //in card component
[text]="{key: 'sdbjvbjhbvsdbv'}"? - Abhishektext.keyfor get value? - Abhishek