在Stackbliz上将OpenRouteService添加到Angular应用程序

时间:2019-12-27 00:28:06

标签: javascript angular api npm

我在我的Stackbliz应用程序中添加了import { Component, OnInit } from '@angular/core'; import {Location} from '@angular/common'; import {Openrouteservice} from '/openrouteservice-js/dist/ors-js-client'; @Component({ selector: 'app-event-plan', templateUrl: './event-plan.component.html', styleUrls: ['./event-plan.component.scss'] }) export class EventPlanComponent implements OnInit { constructor(private _location: Location) { console.log("++++") console.log(Openrouteservice) } ngOnInit() { } backClicked() { this._location.back(); } } ,但无法正常运行。 组件看起来像:

{{1}}

我的问题是它没有被加载。我在依赖项部分将其添加为依赖项。

我将项目公开了,这里是URL-https://stackblitz.com/edit/angular-micwge?file=src%2Fapp%2Fevent-plan%2Fevent-plan.component.ts

1 个答案:

答案 0 :(得分:1)

您将不得不更改import库的方式。您import当前的方法是从库中查找命名导出。

如果您的allowSyntheticImports中有esModuleInteroptsconfig.json,请使用以下方法:

import Openrouteservice from 'openrouteservice-js';

否则:

import * as Openrouteservice from 'openrouteservice-js';

找到您的forked stacknlitz