-1
我想模擬一個登錄組件,它執行一個http身份憑證,並返回一個包含令牌和其他信息的JSON對象。InMemoryBackendService錯誤collection.reduce不是一個函數
得到一個「500內部服務器錯誤」的迴應,經進一步檢查我看到在響應主體更多信息...
error:"collection.reduce is not a function"
這裏是我的種子數據文件
export class AppData {
createDb() {
let auth = {
access_token: '2YotnFZFEjr1zCsicMWpAA',
token_type: 'bearer',
expires_in: 3500
};
return {auth};
}
}
auth.service.ts
public authenticateUser(user:string, pass:string):Promise<AuthResponseModel> {
// TODO: Hit auth endpoint
let authUrl = 'app/auth';
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
let body = JSON.stringify({ username: user, password: pass});
return this.http.post(authUrl, body, options)
.toPromise()
.then((res: Response) => {
let body = res.json();
return body.data || { };
},(reason:any) => {
console.log('authenticateUser() error %o ', reason);
return Promise.reject(reason);
})
.catch(this.handleError);
}