尝试将img [src]绑定到Angular中的Ng模块,以便可以将图像作为formGroup的一部分

我正在尝试将img [src]绑定到ngModel,因此可以将其作为表单的一部分提交。该用户个人资料图像是从数据库下载的,并且该图像正在视图中显示。但是我不能将图像绑定到ngModel。

我已经在下面尝试了此代码,但无法正常工作。在这段代码中,我尝试绑定显示的个人资料图像,并获取其值并将其绑定到ngModel。

我收到以下错误。

尝试将img [src]绑定到Angular中的Ng模块,以便可以将图像作为formGroup的一部分

home.html

   <form  id ="ngForm" [formGroup]="validations_form" 
     (ngSubmit)="onSubmit(validations_form.value)" novalidate>
                       <ion-item color="dark">
                          <ion-label position="floating">Say 
             Something</ion-label>
                          <ion-input type="text" 
         formControlName="description"  color="light"></ion-input>
                          </ion-item>
                           <ion-item color="dark" *ngFor="let value 
                         of students">
                        <ion-label position="floating"></ion-label>
                     <ion-input type="text" 
              formControlName="username" 
          [(ngModel)]="value.username" color="light"></ion-input>

  <div  *ngFor= "let value of students">
      <img [src]= "value.profileImage" [(ngModel)]="item.username">
    </div> 
   <ion-button class="submit-btn" 
    expand="block" type="submit" color="medium-tint" form="ngForm"  
    style="display: none;">Create</ion-button> 
</form>

home.ts

 onSubmit(value){
    //make button dissapear 
    let data = {
      username : value.username || "",description: value.description,profileImage: value.profileImage,image: this.image,category: this.category
    }
    this.firebaseService.createtask(data)

Firebase服务Ts。

  createtask(value) {
    return new Promise<any>((resolve,reject) => {
      let currentUser = firebase.auth().currentUser;  
      this.afs.collection('tasks')
      .add({
        profileImage: value.profileImage,username: value.username,uid: currentUser.uid,date: new Date()
      })
      .then(
        res => resolve(res),err => reject(err)
      )
    })
  }
slxy2009 回答:尝试将img [src]绑定到Angular中的Ng模块,以便可以将图像作为formGroup的一部分

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3163592.html

大家都在问