Search code examples
angulartypescriptinputcomponents

What is the difference between passing constants as Props in Angular?


While I was working with a dx-calendar component from DevExtreme, I face an issue. I just wanted to pass 1 to firstDayOfWeek of that component in order to set Monday as the first day of the week. So I tried:

<dx-calendar firstDayOfWeek="1" />

But it didn't work and the solution was:

<dx-calendar [firstDayOfWeek]="1" />

I thought they both are passing 1 to the component, but the behavior was different.

Related Question here


Solution

  • I found the differences between them. So the first one is passing a string "1" to the component and the second one was passing a number 1 to the component.

    When we use [] for the attributes in Angular, the value is a kind of expression, and what's actually inputted to the component eval("1") that is 1.