我试图进入离子。现在我遇到了一个问题:我有一个loginpage + controler(login.ts),autentification的提供者(auth.ts)和http请求的提供者(http-request.ts)。这是代码:
login.ts
login(user_name, user_password){
this.auth.login(user_name, user_password);
}
auth.ts
login(user_name, user_password)
{
let fields_db = 'user_id,user_displayname,user_firstname,user_lastname,user_password,user_email,user_gender,user_city,user_dateofbirth,user_dateofregistry,user_dateoflastlogin,user_image,user_status';
let filters_db = '(user_displayname='+ "Jon" +') and (user_password='+ "123456" +')';
let tablename = 'user';
return this.httpRequest.get(fields_db, filters_db, tablename).subscribe(
result => {
this.userdataprovider.setLoggedUser(result);
console.log(result);
return result;
},
error => {
console.log('Error bei der Authentifizierung ' + error);
return error;
}
);
}
HTTP-request.ts
request = (req) => {
let baseUrl = REST_BASE_URL,
requestOptions = new RequestOptions({
method: req.method,
url: baseUrl+req.url,
headers: req.header ? req.header : this.getHeader(),
body: req.params
});
return this.http.request(new Request(requestOptions)).map((res:Response) => res.json());
}
get(fields_db, filters_db, tablename){
let params = {
filter: filters_db,
fields: fields_db
};
return this.request({method: 'GET', url: (TABLE_URL_PART + tablename), params: params});
}
Http提供了一个结果,然后我订阅了。但每次登录时我都会定义。我可以在控制台上看到:console.log(this.auth.login(user_name,user_password));
我如何实现登录以订阅auth功能或数据,我从http获取?什么是最好的解决方案。
非常感谢:)