2016-01-21 28 views

回答

96

将事件绑定到DOM时使用(eventName),基本上()用于事件绑定。也可以使用ngModel来获得myModel变量的双向绑定。

标记

<input type="text" [(ngModel)]="myModel" (blur)="onBlurMethod()"> 

代码

export class AppComponent { 
    myModel: any; 
    constructor(){ 
    this.myModel = '123'; 
    } 
    onBlurMethod(){ 
    alert(this.myModel) 
    } 
} 

Demo

替代(不优选)

<input type="text" #input (blur)="onBlurMethod($event.target.value)"> 

Demo


对于模型驱动的形式开枪blur验证,你可以通过updateOn参数。

ctrl = new FormControl('', { 
    debounce: 1000, 
    updateOn: 'blur', //default will be change 
    validators: [Validators.required] 
}); 

Design Docs

+2

(模糊)事件不会在IE11工作。任何工作? –

+4

刚刚在IE11(11.0.9600)上测试过,它的工作完美无瑕! – Timigen

+4

反应形式怎么样?如何以反应形式做到这一点。 – ATHER

0
/*for reich text editor */ 
    public options: Object = { 
    charCounterCount: true, 
    height: 300, 
    inlineMode: false, 
    toolbarFixed: false, 
    fontFamilySelection: true, 
    fontSizeSelection: true, 
    paragraphFormatSelection: true, 

    events: { 
     'froalaEditor.blur': (e, editor) => { this.handleContentChange(editor.html.get()); }} 
0

您可以输入标签直接使用(模糊)事件。

<div> 
    <input [value] = "" (blur) = "result = $event.target.value" placeholder="Type Something"> 
    {{result}} 
</div> 

,你会得到 “结果” 输出