Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度2 |使用大写指令后返回空值_Angular_Angular Formly - Fatal编程技术网

Angular 角度2 |使用大写指令后返回空值

Angular 角度2 |使用大写指令后返回空值,angular,angular-formly,Angular,Angular Formly,为什么在使用指令时返回空值?我在这里使用formController 请看下面的代码示例 指令 import { Directive, HostListener, ElementRef, Output, EventEmitter } from '@angular/core'; @Directive({ selector: '[uppercase]' }) export class UppercaseDirective{ @Output() ngModelChange =

为什么在使用指令时返回空值?我在这里使用formController

请看下面的代码示例

指令

import { Directive, HostListener, ElementRef, Output, EventEmitter } from '@angular/core';

@Directive({
    selector: '[uppercase]'
})    
export class UppercaseDirective{
    @Output() ngModelChange = new EventEmitter<any>();
    value: any;

    constructor(
        private el: ElementRef
    ){}

    @HostListener('input', ['$event']) onInputChange($event) {
        this.value = $event.target.value.toUpperCase();
        this.ngModelChange.emit(this.value);
    }
}
import{Directive,HostListener,ElementRef,Output,EventEmitter}来自“@angular/core”;
@指示({
选择器:“[大写]”
})    
导出类大写指令{
@Output()ngModelChange=neweventemitter();
价值:任何;
建造师(
私人el:ElementRef
){}
@HostListener('input',['$event'])onInputChange($event){
this.value=$event.target.value.toUpperCase();
this.ngModelChange.emit(this.value);
}
}
component.html

<div class="col-lg-4">
      <small [ngClass]="{'prompterror': storageForm.controls.id.valid || storageForm.controls.id.pristine}">
     *required
      </small>
    <div class="input-group">
      <input type="text" class="form-control input-field" placeholder="Storage ID" [(ngModel)]="storageForm.value.id" formControlName="id" required uppercase>
      <span class="input-group-btn" (click)="showModal()">
        <i class="btn glyphicon glyphicon-search"></i>
      </span>
    </div>
  </div>

*必需的

它在哪里返回null?如果将
console.log(this.value)
放在
onInputChange
方法中,它会输出什么?我在这里发现了我的错误[(ngModel)]=“storageForm.value.id”,似乎它没有将值发送回存储表单。然后用这种方式修复它<代码>