Why are my component bindings undefined in its controller?

前端 未结 9 1785
醉梦人生
醉梦人生 2021-01-31 13:22

I\'m writing a simple angular component. I\'m passing a parameter as a binding and display its value on the screen. All works fine: I can see the parameter being displayed on th

9条回答
  •  不思量自难忘°
    2021-01-31 13:52

    The keyword this doesn't seem to works with arrow function, this works with

    controller: function() {
       alert('contact id from controller: ' + this.contactId);
    }
    

    When using arrow function, this, seems to refer to the window object because

    An arrow function does not create it's own this context, rather it captures the this value of the enclosing context

提交回复
热议问题