代码之家  ›  专栏  ›  技术社区  ›  Lucien Dubois

离子相机:没有值存取器的形式控制与名称

  •  0
  • Lucien Dubois  · 技术社区  · 7 年前

    我用的是 cordova插件相机 离子型应用程序中的插件。我成功地让相机拍了一张照片,并在出现以下错误后显示出来:

    No value accessor for form control with name 'photo'
    

    注册.html

    <img *ngIf="register_form.controls.photo.value != ''" formControlName="photo" [src]="domSanitizer.bypassSecurityTrustUrl(register_form.controls.photo.value)" />
    

    register.ts文件

    ionViewWillLoad() {
      this.register_form = this.formBuilder.group({
        ...
        photo: new FormControl('', Validators.required)
      });
    }
    ...
    onTakePicture(){
      ...
      this.camera.getPicture(options).then((imageData) => {
            const image: FormControl = (<any>this.register_form).controls.photo;
            image.setValue('data:image/jpeg;base64,' + imageData);
        }, (err) => {
      });
    }
    

    怎么了?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Sunil Singh    7 年前

    formControlName 只能用于控制或 directives 哪个实现了 ControlValueAccessor . 因为您使用的是img,它不实现 ,您不能在此处使用。

    更多信息请访问- https://angular.io/api/forms/ControlValueAccessor