javascript - Observable.subscribe() 在 IE 中无法在 Angular 7 中更改组件
问题描述
我有两个 HTML 按钮“上一个”和“下一个”。我使用这些按钮导航到不同的选项卡(组件)。该代码在 Chrome 和 Firefox 中按预期工作,但在 IE 或 Edge 中单击下一个和上一个按钮时会出现空白屏幕。
“下一步”按钮事件处理程序:
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();
}
模板
<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>
组件.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();
}
}
解决方案
尝试使用 polyfill,它们对于 IE 和 Edge 是必需的,因为它们缺少一些 es6/7 功能
在 polyfills.ts 文件中导入它
import 'core-js/es7/array';
import 'core-js/es7/object';
import 'core-js/es6/reflect';
import 'core-js/es7/reflect';`
推荐阅读
- laravel - 了解传递给 Vue 子组件的路由器视图的道具,道具数据未呈现
- javascript - Load dynamic Vue routes from json file
- c# - 画布 ui 操纵杆元素的 X 轴旋转不起作用,而 Y 轴在 Unity 中起作用
- sql - 当所有元组在重复项和原始元组中都相同时,如何删除重复项但保留一个?在PostgreSQL中
- exception - 程序从指定文本中删除字符时出现异常
- javascript - 如何不允许在 JavaScript 中连续按下两个键?
- reactjs - NPM 安装在这个 VSCode 项目中发疯,请指教
- c# - 仅发布模式下的 UWP 异常
- linux - 如何将参数传递给下载的脚本
- python - 类型提示 Callable 无参数