我正在尝试将email
和password
变量的值设置为userreg
,其类型为UserRegister
应该采用电子邮件和密码
参数。
错误:类型“string”无法分配给类型“UserRegister”。
,无法重新声明 block 范围变量“password”。
export class UserRegister {
email: string = '';
password: string = '';
}
let email = '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="116574626551657462653f727e7c" rel="noreferrer noopener nofollow">[email protected]</a>';
let password = 'testpass';
let userreg: UserRegister = email, password;
private doRegister(): void {
this.Authentication.register(userreg)
.catch((message: string) => this.formError = message);
}
最佳答案
你的值(value)分配应该是
const uEmail = '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="433726303703372630376d202c2e" rel="noreferrer noopener nofollow">[email protected]</a>';
const uPassword = 'testpass';
const userreg: UserRegister = {email: uEmail, password: uPassword };
关于angular - 如何给类属性赋值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65965418/