简体   繁体   English

没有用于ngControl的未指定名称属性的表单控件的值访问器

[英]No value accessor for form control with unspecified name attribute for ngControl

I'm creating an Ionic social app. 我正在创建一个Ionic社交应用。 You upload a pic to a firebase backend. 您将pic上传到firebase后端。 I'm getting the following error message when go to the profile page: No value accessor for form control with unspecified name attribute. 转到配置文件页面时收到以下错误消息:没有带有未指定名称属性的表单控件的值访问器。

So when the page loads, if there's no download url from firebase it should return the image location to use the default button image. 因此,当页面加载时,如果没有来自firebase的下载URL,则应返回图像位置以使用默认按钮图像。 If there's an image in firebase for photo0 then it should use that url. 如果firebase中有photo0的图像,那么它应该使用该URL。 The NGModel should dynamically change whenever a user uploads or deletes the pic. 每当用户上传或删除pic时,NGModel都应该动态地改变。 But when I load that page I get the no value accessor error. 但是当我加载该页面时,我得到了无值访问器错误。 Not sure what I'm doing wrong here. 不知道我在这里做错了什么。

 import { Component, OnInit } from '@angular/core'; import { AuthService } from '../../services/user/auth.service'; import { ImageService } from '../../services/image.service'; import { Router } from '@angular/router'; import * as firebase from 'firebase/app'; import { AngularFireAuth } from 'angularfire2/auth'; public photo0: string; constructor(private router: Router, private authService: AuthService, private imageService: ImageService, private afAuth: AngularFireAuth) { this.afAuth.authState.subscribe(user => { this.userId = user.uid console.log('constructoruser', this.userId); }); } ngOnInit() { this.firestore.ref(`/Photos/${ this.userId }/`).child('photo0').getDownloadURL().then((url) => { this.photo0 = url; }).catch((error) => { console.log(error.message); this.photo0 = 'assets/img/add-an-image.png'; console.log(this.photo0); }); } 
  <div> <div [(ngModel)]="photo0"> <img src="photo0" (click)="UploadPic0('photo0')"/> </div> </div> 

you can try with: 你可以尝试:

    <div>
        <div *ngIf="photo0 != ''">
            <img [src]="photo0" (click)="UploadPic0('photo0')"/>
        </div>      
    </div>

the tag "src" must to receive a component value. 标签“src”必须接收组件值。 You can use [src]="photo0" or src="{{photo0}}" inside of your img tag. 您可以在img标签内使用[src]="photo0"src="{{photo0}}"

Got rid of the error by removing ngModule and just using the following: 通过删除ngModule并使用以下内容消除错误:

            <div>
                <img [src]="photo0" (click)="UploadPic0('photo0')"/>
            </div>   

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 没有用于未指定名称属性Angular 2的表单控件的值访问器 - No value accessor for form control with unspecified name attribute Angular 2 错误错误:具有未指定名称属性的表单控件没有值访问器 - ERROR Error: No value accessor for form control with unspecified name attribute 没有用于角度控制的格式控件的值访问器(角度5中具有未指定的名称属性) - No value accessor for form control with unspecified name attribute in angular 5 Angular 7-具有未指定名称属性的表单控件无值访问器 - Angular 7 - No value accessor for form control with unspecified name attribute Angular 7 Reactive 表单“没有未指定名称属性的表单控件的值访问器” - Angular 7 Reactive forms “No value accessor for form control with unspecified name attribute” ERROR 错误:在开关上没有具有未指定名称属性的表单控件的值访问器 - ERROR Error: No value accessor for form control with unspecified name attribute on switch 表单控件错误:错误错误:没有具有未指定名称属性的表单控件的值访问器 - form control error:ERROR Error: No value accessor for form control with unspecified name attribute 以Angular格式显示img会显示“没有用于未指定名称属性的窗体控制的值访问器” - Displaying img in Angular form gives “No value accessor for form control with unspecified name attribute” 有角材料Datepicker引发多个自定义值访问器将表单控件与未指定名称属性相匹配 - Angular material Datepicker throws More than one custom value accessor matches form control with unspecified name attribute ERROR 错误:在 angular 中绑定轮播时,没有具有未指定名称属性的表单控件的值访问器 - ERROR Error: No value accessor for form control with unspecified name attribute when bind carousel in angular
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM