[英]Observable.subscribe() not working in IE on component change in Angular 7
I have two HTML buttons 'previous' and 'next'.我有两个 HTML 按钮“上一个”和“下一个”。 I have different tabs (components) to which I navigate to using these buttons.
我使用这些按钮导航到不同的选项卡(组件)。 The code works as expected in Chrome and Firefox but it gives a blank screen when clicking next and previous buttons in IE or Edge.
该代码在 Chrome 和 Firefox 中按预期工作,但在 IE 或 Edge 中单击下一个和上一个按钮时会出现空白屏幕。
'next' button event handler: “下一步”按钮事件处理程序:
saveAndNextClick(form: FormGroup, section: string) {
this.markFormGroupTouched(form);
if (form) {
if (section === 'lastsection') {
this.sectionChangeService.change('schoolSection');
} else {
this.hideShowTabSection();
this.selectedSectionGroup[section] = false;
}
}
this.saveData();
this.saveService.saveQuestion();
}
Template模板
<div class="d-flex app-question-navigation justify-content-between">
<a class="btn btn-secondary buttonSize (click)="previousClick(appSectionThree,'sectionTwo')">
Previous
</a>
<span class="app-question-pagination">Section 3 of 8</span>
<a class="btn btn-secondary buttonSize" (click)="saveAndNextClick(appSectionThree,'sectionFour')">
Next
</a>
</div>
</form>
component.ts组件.ts
ngOnInit() {
this.sectionChangeService.listen().subscribe((message: any) => {
if (message.text === 'prvsparentdemosection') {
this.saveAndNextClick(this.pdemographicsSectionFive, 'sectionFour');
}
});
}
Service:
```typescript
import { Injectable } from '@angular/core';
import { Observable, Subject } from 'rxjs';
@Injectable({ providedIn: 'root' })
export class SectionChangeService {
private listner = new Subject<any>();
change(message: string) {
this.listner.next({ text: message });
}
clearListner() {
this.listner.next();
}
listen(): Observable<any> {
return this.listner.asObservable();
}
}
Try using polyfills, they are necessary for IE & Edge because they lack some es6/7 functions尝试使用 polyfills,它们对于 IE 和 Edge 是必需的,因为它们缺少一些 es6/7 功能
Import this in the polyfills.ts file在 polyfills.ts 文件中导入
import 'core-js/es7/array';
import 'core-js/es7/object';
import 'core-js/es6/reflect';
import 'core-js/es7/reflect';`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.