我正在使用RXJS 5,现在当我升级到6时,我遇到了一些问题.
以前我能够使用catch和最后但是根据更新catch用catchError替换(在管道中)现在如何使用finally?
我也有一些问题:
我是否需要更改throw-> throwError(在下面的代码Observable.throw(err);)
import { Observable, Subject, EMPTY, throwError } from "rxjs";
import { catchError } from 'rxjs/operators';
return next.handle(clonedreq).pipe(
catchError((err: HttpErrorResponse) => {
if ((err.status == 400) || (err.status == 401)) {
this.interceptorRedirectService.getInterceptedSource().next(err.status);
return Observable.empty();
} else {
return Observable.throw(err);
}
})
//, finally(() => {
// this.globalEventsManager.showLoader.emit(false);
//});
);
Run Code Online (Sandbox Code Playgroud)
另外如何使用publish().refCount()?
我希望检测何时更改了路线并替换了新的view(html)。
尝试过以下代码,但不知道如何继续进行。
this._routerSub = this.router.events
.filter(event => event instanceof NavigationEnd)
//.do(event => console.log(event)) //
.subscribe((value) => { });
Run Code Online (Sandbox Code Playgroud)
还尝试了下面的代码,但出现错误
无法将事件类型的参数分配给类型'(value:Event)=> void'的参数。
import { Router, NavigationEnd, Event } from '@angular/router';
this._routerSub = this.router.events
.subscribe(event : Event) => {
if (event instanceof NavigationEnd) {
console.log(event.url);
}
});
Run Code Online (Sandbox Code Playgroud)
下面的Vega是我的app.component.ts和app.component.ts代码。是不是应该在激活时调用onActivate。由于路由器插座将在实例化新组件时发出激活事件。
app.component.html
<router-outlet (activate)="onActivate($event)" ></router-outlet>
Run Code Online (Sandbox Code Playgroud)
app.component.ts
onActivate(e) {
debugger;
console.log(1);
}
Run Code Online (Sandbox Code Playgroud) 我在 Angular6 中开发了一个项目。需要为实时聊天开发部分。为此,我在我的 asp.net 核心 Web Apiproject 中使用 SignalR。现在我想在我的 Angular 项目中使用这个 Web Api 参考。
我正在使用此链接。
但是在 App.Component.ts 中提供 Web Api url 时,我收到以下错误:
“HubConnection”类的构造函数是私有的,只能在类声明中访问。
应用组件.ts:
import { HubConnection } from '@aspnet/signalr';
import { Message } from 'primeng/api';
export class AppComponent implements OnInit {
public _hubConnection: HubConnection;
msgs: Message[] = [];
constructor() {
}
ngOnInit() {
this._hubConnection = new HubConnection('http://localhost:1874/notify'); // getting error on this line.
Run Code Online (Sandbox Code Playgroud)
编辑:尝试以下代码:-
修改后的 App.Component.ts :
import { HubConnection } from '@aspnet/signalr';
import * as …Run Code Online (Sandbox Code Playgroud) 以下是我的代码,可从服务获得响应。在这里,我得到了员工名单。
我需要根据服务的响应动态地绑定表单控件,我的服务返回的字段(表单中的员工ID,姓名,部门等)比表单控件更多。如何跳过那些不在窗体控件中使用的控件?
this._employeeService.getEmployeeById(this.employeeId).subscribe((res: Response) => {
debugger;
this.employeeForm.get('FileUploader').setValue(null);
//this.employeeForm.setValue(res);
for (const field in res) {
this.employeeForm.controls[field].setValue(res[field]);
}
});
this.employeeForm = this._fb.group({
EmployeeId: 0,
Name: ''});
Run Code Online (Sandbox Code Playgroud)