我有一个日期字段,我想默认删除占位符.
我正在使用javascript onfocus和onfocusout事件来删除占位符.
任何人都可以帮助使用angular2指令吗?
<input name="date" type="text" onfocus="(this.type='date')" onfocusout="(this.type='text')" class="dateinput">
Run Code Online (Sandbox Code Playgroud)
我尝试以这种方式解决,但我遇到重置输入字段类型的问题.
import { Directive, ElementRef, Input } from 'angular2/core';
@Directive({
selector: '.dateinput',
host: {
'(focus)': 'setInputFocus()',
'(focusout)': 'setInputFocusOut()',
}})
export class MyDirective {
constructor(el: ElementRef) { this.el = el.nativeElement; console.log(this.el);}
setInputFocus(): void {
//console.log(this.elementRef.nativeElement.value);
}
}
Run Code Online (Sandbox Code Playgroud) 在Angular2中如何知道任何输入字段何时失去焦点..!如果我在表单上使用observable:
form.valueChange.subscribe...
Run Code Online (Sandbox Code Playgroud)
不会工作,因为我真的想知道什么时候一个字段丢失它的模糊(焦点)所以我可以更新我的商店(如果我在失去焦点之前更新商店,我的光标在文本输入上移动到最后,因为数据被交换这看起来很奇怪)
当然我也可以添加(change)=""每个输入,但我有很多'...
我在考虑各种各样的事情:
this.form.valueChanges.debounceTime(1000).subscribe((changes:any) => {
if (this.form.dirty){
this.appStore.dispatch(this.resellerAction.updateResellerInfo(changes))
}
});
Run Code Online (Sandbox Code Playgroud)
但问题是脏污仍然很脏,所以它陷入了永久性的变化检测循环......
TX
肖恩
angular ×2