我有一个angular7
应用,其中我有一个custom
input
组件,它在多个位置调用,例如component.html
component.ts
handleChange(value) {
this.payment.collectedAmount = value;
this.calculateRemainingBalance();
}
现在我有了指令,我将在其中格式化输入组件的值,但目前我只是在directive
组件的custom
内获取该值,像这样
@Input() currencyValue: any;
constructor(private el: ElementRef) {
}
ngAfterViewInit() {
// this.el.nativeElement.focus();
console.log('currency value : ',this.currencyValue)
}
@HostListener('focus', ['$event.target']) onfocus(){
console.log('in focus');
}
现在,当我运行应用程序并加载页面时,因此directive
仅在页面加载时记录此行console.log('currency value : ',this.currencyValue)
一次,然后在ngAfterViewInit
和HostListener
中都不再记录。我如何从custom
内部的directive
输入组件中获取值?
<input type="text" your-directive />
@Directive({
selector: 'yourSelector'
})
export class TestDirective {
@HostListener('keydown', ['$event']) onKeyDown(e) {
console.log('in focus');
}
}