小编Jei*_*izi的帖子

让用户:User = new User(....)为什么这对我不起作用?

嗨,我正在尝试创建一个新用户,这个语法不起作用,它说'用户'只引用一个类型,但在这里被用作值.

 onSubmit() {
    if (this.userForm.valid) {

        let user: User = new User(null,
        this.userForm.controls['cin'].value,
        this.userForm.controls['familyName'].value,
        this.userForm.controls['givenName'].value,
        this.userForm.controls['email'].value,
        this.userForm.controls['description'].value,
        this.userForm.controls['code'].value);
        this.adminService.createUser(user).subscribe();
     }
  }
Run Code Online (Sandbox Code Playgroud)

export interface User {
  cin: string;
  givenName: string;
  familyName: string;
  role: string;
  id: string; 
  email: string;   
}
Run Code Online (Sandbox Code Playgroud)

这是因为User被声明为接口?我怎么解决它?提前致谢 :)

typescript angular angular5

2
推荐指数
1
解决办法
88
查看次数

标签 统计

angular ×1

angular5 ×1

typescript ×1