Changing Component Property from Directive in Angular2

前端 未结 3 1218
面向向阳花
面向向阳花 2021-01-02 04:49

I have an Angular 1 app that works with a simple contentEditable directive, which can be used like this in templates:



        
3条回答
  •  醉话见心
    2021-01-02 05:23

    If you simply want to change the value using pure JavaScript and do not want to go towards the [(model]) route, then this is for you.

    const input = this.el.nativeElement.querySelector('#myElement');
    input.value = 'My Programmatic Value';
    input.dispatchEvent(new Event('input'));
    

    Issue - https://github.com/text-mask/text-mask/issues/696

    Solution - https://github.com/text-mask/text-mask/issues/696#issuecomment-354887412

    Hope this helps someone.

    Cheers!

提交回复
热议问题