セレクタを'input'
に変更すると、セレクタはすべての入力に適用されます。私が'input[numeric]'
に変更した場合、何も起こりません(はい、input[numeric]
が実際に存在します)。 私は何が間違っていますか?このように動くはずはないのですか?これは、ドキュメントのCSSセレクタを...言うディレクティブセレクタで要素が見つかりません
import {Directive, ElementRef} from '@angular/core';
import {NgModel} from '@angular/common';
@Directive({
selector: 'input[numeric]',
host: {
'(input)' : 'onInputChange()'
}
})
export class NumberFormatDirective {
constructor(public model: NgModel, public element: ElementRef) {
console.log(1);
}
onInputChange(): any {
console.log(2);
}
}
:
<input *ngIf='!isMultiLine()'
[attr.readonly]='readonly'
[attr.disabled]='isInputDisabled()'
[attr.minlength]='minLength'
[attr.maxlength]='maxLength'
[attr.numeric]='isNumeric()'
[(ngModel)]='value' (ngModelChange)='valueChanged($event)'
(keyup.enter)='updateValueRestore()'
(keyup.escape)='resetValue()'
(focus)='onFocus()'
(blur)='onBlur()'
autocomplete='off'/>
「実際に存在する」入力[数値]はどのように正確に見えますか? –
私はhtmlコード – user489872
を追加しました。うまくいくはずです。 Plunkerで再現できますか? –