Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2: Escape character in component's input

Tags:

angular

I have the following code :

<my-comp [title]="Foo's component"></my-comp>

I have tried many things ('', \', \\', \'', ...)to escape the ' in, but I didn't manage to do it. How can I do this ?

like image 471
Scipion Avatar asked Nov 02 '16 15:11

Scipion


2 Answers

It seems that title is a component property, hence it expects a variable or a string. I assume the correct syntax would be:

<my-comp [title]="'Foo\'s component'"></my-comp>

Adding a single quote before and after

like image 111
Meir Avatar answered Nov 16 '22 23:11

Meir


You're binding to the title property, which is probably of type string. What you're actually doing is binding it to a javascript (well.. angular2) expression, which is Foo's component but that's not a valid expression.

What you should be doing is:

  • Either set the component's title property without the binding syntax, simply title="Foo's Component"
  • alternatively, bind it to a string like this: [title]="'Foo\'s component'".
like image 22
Amit Avatar answered Nov 17 '22 01:11

Amit