如何在 Angular 10 的方法中将模型作为输入参数传递?
How to pass model as input parameter in method in Angular10?
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
}
并且在这个登录方法中想要使用 'lm.uName' / 'lm.uPassword'
你可以像下面那样做。
login(lm: LoginModel){
//my post request here
}
因此您必须使用loginModel 类型创建参数。所以
login(lm: LoginModel) {
// lm.uname = 'abc';
// logic here, api call
// etc
}
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
}
并且在这个登录方法中想要使用 'lm.uName' / 'lm.uPassword'
你可以像下面那样做。
login(lm: LoginModel){
//my post request here
}
因此您必须使用loginModel 类型创建参数。所以
login(lm: LoginModel) {
// lm.uname = 'abc';
// logic here, api call
// etc
}