When to use square brackets [ ] in directives @Inputs and when not?

前端 未结 4 1523
猫巷女王i
猫巷女王i 2020-12-02 14:16

I\'m confused a little.

See this simple directive:

 @Directive({
      selector: \'[myDirective]\'
    })
    export class MyDirective {

      priva         


        
4条回答
  •  醉梦人生
    2020-12-02 14:47

    The brackets tell Angular to evaluate the template expression. If you omit the brackets, Angular treats the string as a constant and initializes the target property with that string. It does not evaluate the string!

    Don't make the following mistake:

        
        
    

    check: https://angular.io/docs/ts/latest/guide/template-syntax.html#!#property-binding

提交回复
热议问题