How to pass model as input parameter in method in Angular10?

1.1k views Asked by At
I am having one model(login.model.ts) in my angular project like below - 

export class LoginModel{
    public uName: string;
    public uPassword: string;
}

I want to use this model as input parameter in method called 'login' in my service(authentication.service.ts) from where I am doing **POST** request. How can I do that? May be something like below.

login(LoginModel lm){
  //my post request here
}

And inside this login method want to use like 'lm.uName' / 'lm.uPassword'

2

There are 2 answers

3
Bhavin Hirpara On BEST ANSWER

You can do it like below.

login(lm: LoginModel){
  //my post request here
}
0
Wahab Shah On

So you will have to make the parameter with the type of loginModel. So

login(lm: LoginModel) { 
    // lm.uname = 'abc';
    // logic here, api call
    // etc
  }