我尝试使用浏览器运行单个页面应用程序时出现以下错误(我与Safari以及Chrome相同的问题)。我起诉角cli(角4)和打字稿。我确实有一个独特的组件和一个独特的模块。使用主要组件,我试图从后端请求一些数据。Angular 4应用程序错误:“core.es5.js:1169未捕获错误:PlatformRef没有提供程序!”
从浏览器中提出的问题:
core.es5.js:1169 Uncaught Error: No provider for PlatformRef!
at injectionError (core.es5.js:1169)
at noProviderError (core.es5.js:1207)
at ReflectiveInjector_.webpackJsonp.../../../core/@angular/core.es5.js.ReflectiveInjector_._throwOrNull (core.es5.js:2649)
at ReflectiveInjector_.webpackJsonp.../../../core/@angular/core.es5.js.ReflectiveInjector_._getByKeyDefault (core.es5.js:2688)
at ReflectiveInjector_.webpackJsonp.../../../core/@angular/core.es5.js.ReflectiveInjector_._getByKey (core.es5.js:2620)
at ReflectiveInjector_.webpackJsonp.../../../core/@angular/core.es5.js.ReflectiveInjector_.get (core.es5.js:2489)
at createPlatform (core.es5.js:4239)
at core.es5.js:4265
at core.es5.js:4262
at core.es5.js:4262
误差似乎由下面的行的主模块中喷射出的主组件内部编写的代码引起的: 让解析度=新CalculatorCore()getMaxProfitCurrencyPath(。 500,dataManager.getCalculateDataStructure(“EUR”));
这里CLAS CalculatorCore:
import { Currency } from "./currency";
import { Map } from 'collections/map';
export class CalculatorCore {
private inputOutputCurrency: string = "EUR";
constructor() {
}
getMaxProfitCurrencyPath(price: number, currency: Currency, steps?: number, path?: Currency[]):Map<number,string[]> {
let returningPath: Map<number, string[]> = new Map<number,string[]>();
currency.getConvertibles().forEach((key:Currency, value:number) => {
if (!steps) {
steps = 2;
} else if (steps > 0) {
steps--;
if (currency.getLabel() == this.inputOutputCurrency){
path = [];
}
path.push(key);
this.getMaxProfitCurrencyPath(price*value, key, steps, path);
} else if (steps == 0 && key.getConvertibles().has(this.inputOutputCurrency)){
path.push(key.getConvertibles().get(this.inputOutputCurrency));
returningPath.add(key.getConvertibles().get(this.inputOutputCurrency)*price, path);
}
});
return returningPath;
}
}
这里的组件代码:
import {Component, OnInit} from '@angular/core';
import { KrakenClient } from 'kraken-api/kraken.js';
import {DataManager} from "./data-manager";
import {CalculatorCore} from "./calculator-core";
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit{
ngOnInit(): void {
let dataManager = new DataManager();
let res = new CalculatorCore().getMaxProfitCurrencyPath(500, dataManager.getCalculateDataStructure("EUR"));
console.log(res);
}
constructor(){
console.log("App-component constructor")
}
}
有没有人能解释这个错误吗? 谢谢,
请向我们展示您的组件代码。 – bertrandg
你有从你的应用程序模块导入BrowserModule吗? – bertrandg
嗨,我从我的应用程序模块导入BrowserModule。您还可以在主要问题中看到上面的组件代码。谢谢! –