1

I want to understand the internal working of @Input property's rendering.

If I define a component in Angular, where type and title are @Input properties, how does the component understand that type property's value is string (to be considered as-is) and title property's value is to be fetched from config file's component_title variable?

<my-component #comp [type]='CONFIRMATION' [title]='config.component_title'></my-component>
3
  • Have you tested this? I don't think CONFIRMATION in [type]='CONFIRMATION' is string, it will refer to this.CONFIRMATION Commented Jun 1, 2017 at 12:31
  • Wrap it as [type]="'CONFIRMATION'" in order to pass a string along Commented Jun 1, 2017 at 12:33
  • Ok, got it. My syntax error had my answer. Thank you. Commented Jun 1, 2017 at 12:37

3 Answers 3

5

If you use foo="bar", then bar is considered as a string. The string "bar" is thus passed as the value for the input foo.

If you use [foo]="bar", then bar is considered as an angular expression. The value of the expression bar (so, in this case, the value of the property bar of the component) is thus passed as the value for the input foo.

From these two rules, you can thus deduce that foo="bar" is equivalent to [foo]="'bar'".

Sign up to request clarification or add additional context in comments.

Comments

1

[type] = "'CONFIRMATION'" is used for string. (See the quotes)

Comments

-2

read this to find some solution for you

https://toddmotto.com/passing-data-angular-2-components-input

1 Comment

Not that I have downvoted your answer; but this is not really an answer to the specific question...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.