How to assign value to class properties?

Viewed 113

I'm trying to set values of email and password variables to userreg which is in the type of UserRegister which should take email and password arguments.

Errors: Type 'string' is not assignable to type 'UserRegister'., Cannot redeclare block-scoped variable 'password'.

export class UserRegister {
    email: string = '';
    password: string = '';
    }

let email = 'test@test.com';
let password = 'testpass';
let userreg: UserRegister = email, password; 


private doRegister(): void {
    this.Authentication.register(userreg)
    .catch((message: string) => this.formError = message);
        }
1 Answers

Your value assignation should be

const uEmail = 'test@test.com';
const uPassword = 'testpass';
const userreg: UserRegister = {email: uEmail, password: uPassword };
Related