Reputation: 847
I'm trying to pass a string from my parent component to my child component. The string contains HTML tags with an HTML entity. This is an example of the template in the parent:
<child-component i18n-componentContent="this is a test|for testing" componentContent='my test<sup>®</sup>not working'></child-component>
on the child component side, I have the following:
@Input() public componentContent: string;
...
public ngOnInit() {
console.log(this.componentContent);
}
However, the value of
this.componentContent
is: "my test"
So, not the whole string is passed into the child component.
Why isn't the whole string passed into the child component? What is needed to do to pass the whole string from the parent to the child component?
Upvotes: 1
Views: 859
Reputation: 11184
Try like this :
The following html element is valid to pass into child component.
<child-component i18n componentContent='my test<sup>®</sup>not working'></child-component>
if you are using i18n-componentContent="this is a test|for testing"
inside the html element and Child Component get the my test
. so remove this from html element i18n-componentContent="this is a test|for testing"
then you can pass full string into child component
Upvotes: 1
Reputation: 5044
I guess, you're converting the html tag to html entity before passing the string from parent to child and it is producing the the wrongly formatted string.
Instead that you can do the following:
Don't convert to html entity in your parent component and use encodeURIComponent
function to encode the string in the parent component and in the child component use decodeURIComponent
decode and after that do the conversion to html entity in the child component. I hope this way, you can avoid the problem.
Upvotes: 0
Reputation: 1
It's not a valid string, you need to escape html
componentContent='my test<sup>®</sup>not working'>
Upvotes: 0