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

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

I\'m confused a little.

See this simple directive:

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

      priva         


        
4条回答
  •  旧时难觅i
    2020-12-02 14:49

    binding [] is for objects, without it the value is string. Be careful about types.

    In the code

    you have tried to bind the object, but the object is not available, thus it's value is undefined. On the other hand if you remove binding then the object is gone, you have only a string value assigned to the property.

提交回复
热议问题