莫名其妙的异常005:Uncaught Error: Can't resolve all parameters for ApplicationModule

NgRx/Store 4 + Angular 5,调试时报这个错误:Uncaught Error: Can't resolve all parameters for ApplicationModule。

解决办法:polyfills.ts文件里导入这个包,

import 'core-js/es7/reflect';

 

一个demo,想通过服务实现非父子组件的通信,报这个错误,下面是代码 服务的代码 ``` import { Injectable } from '@angular/core'; import {Observable} from 'rxjs'; import { Subject } from 'rxjs'; @Injectable({ providedIn: 'root' }) export class TransferMessageService { constructor() { } private subject = new Subject<any>(); sendMessage(message: any) { this.subject.next({ text: message }); } clearMessage() { this.subject.next(); } getMessage(): Observable<any> { return this.subject.asObservable(); } } ``` 发送的组件的ts ``` import { Component, OnInit } from '@angular/core'; import {RequestService} from '../../../services/request/request.service'; import {Router} from '@angular/router'; import {TransferMessageService} from '../../../services/common/transferMessage'; @Component({ selector: 'app-login-session-code', templateUrl: './login-session-code.component.html', styleUrls: ['./login-session-code.component.scss'], }) export class LoginSessionCodeComponent implements OnInit { public riskRole: string = localStorage.getItem('userRole'); public sessioncode: any; public token_user: any; constructor( public RS: RequestService, public router: Router, public TMS: TransferMessageService ) {} ngOnInit(): void { } sendMessage(parameters:any):void { this.TMS.sendMessage(parameters); } checkInputCall(){ const api = this.RS.baseURL+ '/login/checkInput'; const token_api= this.RS.baseURL+ '/login/checkToken'; const parameters:object = { "email": localStorage.getItem('email'), "input": this.sessioncode, "type": localStorage.getItem('type') } this.RS.checkInput(api,parameters).subscribe(res => { if(res['data'].input_check) { localStorage.setItem('checkInput', JSON.stringify(res['data'])); this.RS.checkToken(token_api,{"token": res['data'].user.token}).subscribe(res => { this.token_user = res; console.log(1); this.sendMessage(JSON.stringify(res)); this.router.navigate(['/home']); // console.log(res); //return token_user }) }else { alert("session code is not true"); } }) } } ``` 接收组件的ts ``` import { Component, OnInit } from '@angular/core'; import { Router } from '@angular/router'; import {TransferMessageService} from '../../services/common/transferMessage'; import {Subscription} from 'rxjs'; @Component({ selector: 'app-home', templateUrl: './home.component.html', styleUrls: ['./home.component.scss'], }) export class HomeComponent implements OnInit { public ctrlHomeDetailTag: boolean = true; public ctrlHomeBasicTag: boolean = true; public ctrlTags: boolean = true; public receiveMsg: any; constructor( public router: Router, public TMS: TransferMessageService, public Subscription: Subscription ) { } ngOnInit(): void { const receiveMsg = this.TMS.getMessage(); console.log(receiveMsg,'parameters'); } ngAfterViewInit():void { this.Subscription = this.TMS.getMessage().subscribe(message => { this.receiveMsg = JSON.parse(message); console.log('this.receiveMsg', this.receiveMsg); }) } } ```
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页