在 Angular 6 中使用最新版本的 rxjs 时遇到问题。
import { Observable, throwError } from "rxjs";
import { map, filter, catchError, mergeMap } from 'rxjs/operators';
isValidUser(user, password) : Observable<any> {
let urlString = "http://localhost....=" + user + "&password=" + password;
console.log(urlString)
return this._http.get(urlString, {withCredentials: true, responseType: 'json'})
.pipe(
map((val: any[]) => {
console.log("val",val);
if (val.hasOwnProperty("GoldUser")) {
if (val["GoldUser"][0]["_Qy"] == "GoldSecurityUser")
this.isUserLoggedIn = true;
return true;
}
return false;
}), catchError( error => {
console.log("error",error );
return throwError( 'Something went wrong!' )
})
);
}
Run Code Online (Sandbox Code Playgroud)
问题是,即使 URL 有效并且一个简单的浏览器 rest 调用返回 json 数据,代码也没有返回任何内容。它永远不会命中我的 console.log val 语句。在 Chrome 中,开发者工具网络选项卡也没有显示任何活动。这是我第一次使用 Angular6 和 rxjs V6 管道,对此我有点困惑。
任何帮助将不胜感激。
ng --version
Angular CLI: 6.0.8
Node: 8.9.4
OS: win32 x64
Angular: 6.0.4
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.6.8
@angular-devkit/build-angular 0.6.8
@angular-devkit/build-optimizer 0.6.8
@angular-devkit/core 0.6.8
@angular-devkit/schematics 0.6.8
@angular/cli 6.0.8
@ngtools/webpack 6.0.8
@schematics/angular 0.6.8
@schematics/update 0.6.8
rxjs 6.2.1
typescript 2.7.2
webpack 4.8.3
Run Code Online (Sandbox Code Playgroud)
顺便说一句,我已经查看了 rxjs 迁移页面,但仍然看不到我做错了什么......
谢谢,
标记。
| 归档时间: |
|
| 查看次数: |
2250 次 |
| 最近记录: |