[英]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.