Angular 2: Difference between property binding with and without brackets?

后端 未结 5 528
失恋的感觉
失恋的感觉 2020-12-16 10:39

I noticed it\'s possible to property bind stuff without brackets. What is the difference?

Typescript:

import { Component, Input } from \'@angular/cor         


        
5条回答
  •  死守一世寂寞
    2020-12-16 11:27

    Here is brief description of all situation:

    When you use square brackets, the right hand side is an expression. When you use no brackets at all, the right hand side is a constant.

    So will assign 'constant' string to my-tag's input. To achieve the same effect with square brackets: notice the single quote inside. If you didn't put single quote there, my-tag's input will be tied to its parent component's (where you write this template) property or template variable (like ngFor's let-constant for example) named "constant".

    form here What is the difference between property binding and just a regular attribute

提交回复
热议问题