错误 TS2339:类型“ElementRef<any>”上不存在属性“value”

时间:2021-03-24 15:18:21

标签: angular ionic-framework

我有这个问题:

错误 TS2339:类型“ElementRef”上不存在属性“value”。

我有一个带有此代码的 .html 文件:

<ion-content>
  <ion-input placeholder="Enter Name" type="text" #name name="name" ></ion-input>
  <ion-input placeholder="Enter Surname" type="text" #surname name="surname" ></ion-input>
  <ion-input placeholder="Enter Type" type="text" #type name="type" ></ion-input>
  <ion-button (click)="addNewUser()">Add New User</ion-button>

和带有此代码的文件 .ts:

export class FirstPage implements OnInit {

  springUsers: SpringUser[];
  @ViewChild('name') name: ElementRef;
  @ViewChild('surname') surname: ElementRef;
  @ViewChild('type') type: ElementRef;
  
  ///[...]
  
  
  addNewUser(){
    console.log('addNewUser');
    let tempUser: SpringUser;
    tempUser = {
      name: this.name.value,
      surname: this.surname.value,
      type: this.type.value,
      email: 'email@gmail.com',
      password: '',
      passwordToVerify: ''

    } ;

    tempUser.name = this.name.value;
    tempUser.surname = this.surname.value;
    tempUser.type = this.type.value;

    this.springUserService.postSpringUser(tempUser).subscribe(data => {
      console.log('inserted user', data);
    });

1 个答案:

答案 0 :(得分:1)

按照文档 (docs) 尝试 https://localhost:9443/authenticationendpoint/login.doresponse_type=code&client_id=myclient_id&scope=profile&redirect_uri=http://localhost/gatewaytest/Home/WsoCallBack 。这基本上适用于您所有的 this.name.nativeElement.value 调用。

相关问题