Angular 启动输入控件上下文菜单粘贴-ngModel

Angular 启动输入控件上下文菜单粘贴-ngModel,angular,primeng,Angular,Primeng,我正在使用Priming输入控件p-spinner,p-calendar。不幸的是,当我用鼠标从上下文菜单中选择粘贴选项时,[ngModel]=“value”绑定没有启动。即使我点击失控,失去焦点也不会被考虑在内。 ctrl+v键盘操作很好,但鼠标/上下文菜单选项更重要。 请帮忙。 我的当前版本: 启动:^4.1.3,日历输入字段如下所示: <input #inputfield type="text" [attr.id]="inputId"

我正在使用Priming输入控件p-spinner,p-calendar。不幸的是,当我用鼠标从上下文菜单中选择粘贴选项时,[ngModel]=“value”绑定没有启动。即使我点击失控,失去焦点也不会被考虑在内。 ctrl+v键盘操作很好,但鼠标/上下文菜单选项更重要。 请帮忙。 我的当前版本:
启动:^4.1.3,

日历输入字段如下所示:

<input #inputfield 
       type="text" 
       [attr.id]="inputId" 
       [attr.name]="name" 
       [attr.required]="required" 
       [value]="inputFieldValue" 
       (focus)="onInputFocus($event)" 
       (keydown)="onInputKeydown($event)" 
       (click)="datepickerClick=true" 
       (blur)="onInputBlur($event)"
       [readonly]="readonlyInput" 
       (input)="onUserInput($event)" 
       [ngStyle]="inputStyle" 
       [class]="inputStyleClass" 
       [placeholder]="placeholder||''" 
       [disabled]="disabled" 
       [attr.tabindex]="tabindex"
       [ngClass]="'ui-inputtext ui-widget ui-state-default ui-corner-all'">
然后输入=onUserInput$事件

看起来IE 11解决方案会导致更多的问题,比如通过右键单击粘贴。因此,作为解决方案,设置this.isKeydown=true;输入时粘贴事件

导入日历和ViewChild:

import { Component, NgModule, ViewChild } from '@angular/core';
import { CalendarModule, Calendar } from 'primeng/primeng';
获取p日历参考: HTML:

在ngAfterViewInit钩子中注册粘贴侦听器:

现在应该行了

普朗克:

微调器的更新

将微调器引用添加为@ViewChild 在微调器引用上注册onpaste侦听器

export class App implements OnAfterViewInit {
  @ViewChild('calendarRef') calendarRef: Calendar;
  @ViewChild('spinnerRef') spinnerRef: Spinner;

  value: Date;

  ngAfterViewInit() {
    this.calendarRef.inputfieldViewChild.nativeElement.onpaste = (e) {
      this.calendarRef.isKeydown = true;
    }

    this.spinnerRef.el.nativeElement.onpaste = (event) {
      setTimeout(_ => {
        this.spinnerRef.onInput(event, event.target.value);
      });
    }
  }
}
也更新


参考onInput函数:

这有助于p-calendar,但关于p-spinner,我仍然不知道。这里没有输入元素的ViewChild句柄:即使我们通过spinner.el.nativeElement.children['0'].children['0']-实现不同请更新我的plunker或创建一个新的plunker或以其他方式共享您的代码,我将尝试使用p-spinner解决方案帮助我更新我的答案和plunker
import { Component, NgModule, ViewChild } from '@angular/core';
import { CalendarModule, Calendar } from 'primeng/primeng';
<p-calendar #calendarRef [(ngModel)]="value"></p-calendar>
@ViewChild('calendarRef') calendarRef: Calendar;
ngAfterViewInit() {
  this.calendarRef.inputfieldViewChild.nativeElement.onpaste = (e) {
    this.calendarRef.isKeydown = true;
  }
}
export class App implements OnAfterViewInit {
  @ViewChild('calendarRef') calendarRef: Calendar;
  @ViewChild('spinnerRef') spinnerRef: Spinner;

  value: Date;

  ngAfterViewInit() {
    this.calendarRef.inputfieldViewChild.nativeElement.onpaste = (e) {
      this.calendarRef.isKeydown = true;
    }

    this.spinnerRef.el.nativeElement.onpaste = (event) {
      setTimeout(_ => {
        this.spinnerRef.onInput(event, event.target.value);
      });
    }
  }
}