Travis Parks
Travis Parks

Reputation: 8695

Angular 2 - Passing Plain Text to Input

In AngularJS, you could specify @ (instead of =) in a directive in order to bind to plain text. So, with field: '@', you could set the scope.field value to the string "Hello, World" with the following HTML:

<my-tag field="Hello, World" />

In Angular 2, I am currently doing the following:

<my-tag [field]="'Hello, World'" />

Notice the single quotes inside the double quotes. Angular 2 is expecting the contents of the attribute to be an expression.

I was wondering if there is a short-hand to treat the attribute values as plain text? This will help avoid the mistake of forgetting the quotes, which I keep making.

Upvotes: 4

Views: 1626

Answers (1)

trees_are_great
trees_are_great

Reputation: 3911

Atleast in the latest version, you can do this in Angular 2 too:

<my-tag field="Hello, World" />

Upvotes: 2

Related Questions