私はプロバイダにいくつかの問題があります。コンポーネントで新しいカスタムプロバイダをインポートしようとしましたが、機能しません。 この第二のプロバイダは私が作ったとうまく動作最初のものに基づいています...無効なプロバイダ
これは私のプロバイダである:
import { Injectable} from "@angular/core";
import { Router, Routes } from '@angular/router';
import ... // All components needed
@Injectable()
export class RoutesHelper {
private userRoutes: Routes = [
{ path: '' , component: HeaderComponent, outlet: 'header' },
...
];
constructor(
private router:Router
) {}
public load() {
this.router.resetConfig(this.userRoutes);
}
}
そして、これが私の「QuestionComponent」
import { Component, OnInit } from '@angular/core';
import { RoutesHelper } from '../_utils/routes.helper';
@Component({
selector: 'questions-list',
templateUrl: './app/question/questions.component.html',
providers: [RoutesHelper]
})
export class QuestionsComponent implements OnInit {
constructor(private routes:RoutesHelper) {}
ngOnInit() {
this.routes.load();
}
}
ですが私はこのエラーがあります: "QuestionsComponent"のプロバイダが無効です - プロバイダとタイプのインスタンスのみが許可されています:[?undefined?]
なぜ私は "未定義"のオブジェクトを持っていないのか分かりません。このエラーもありません。
ありがとうございました。
あなたはプロバイダをapp.module.tsファイルに含めましたか? –
はい、プロバイダーはアプリに含まれています; module.ts – Maxime
プロバイダーリストにも同様にリンクをインポートしていますか? –