Angular5:未捕获错误:无法解析StoresComponent的所有参数:(?,?)

时间:2017-11-30 14:30:12

标签: angular typescript dependency-injection

将我的项目从角度2.3更新为角度5(并解决了许多相关问题)后,我在启动项目时遇到错误:

Uncaught Error: Can't resolve all parameters for StoresComponent: (?, ?).

我在构造函数中有一个带有两个参数的StoresComponent。他们都是自己的提供者。如果我从其构造函数中删除所有参数,我会得到另一个组件的相同错误:

Uncaught Error: Can't resolve all parameters for StoresUsersComponent: (?, ?, ?, ?).

我还没有进一步关注(从这里删除参数,看看会发生什么,但我想我的提供商或DI配置有一些与angular5不相似的东西。)我有几个搜索结果说这个是某种循环参考问题,但我不知道如何检测什么是参考什么?

我的提供商有关键字@Injectable(),app.module包含提供者数组中的提供者。不幸的是我还遇到了其他几个问题,我不知道导致这种情况的变化是什么,但我根据角度更新指南尝试从Http移动到HttpClient

其中一个提供者应注入以下两个组件:

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Store } from '../interfaces/store.interface';
import { StoreResultModel } from '../interfaces/store-result-model.interface';

@Injectable()
export class StoreProvider {
    constructor(private http:HttpClient) {}

storeusers.component.ts:

import { Component, ViewChild, ElementRef } from '@angular/core';
import { DatePipe } from "@angular/common";

import { NavMenuComponent } from '../navmenu/navmenu.component';
import { ProjectUserAddComponent } from "../modals/projectuser-add/projectuser-add.component";

import { StoreUser } from '../../interfaces/StoreUser.interface';

import { StoreUserProvider } from "../../providers/storeuser-provider";
import { StoreUserResultModel } from "../../interfaces/storeuserresult-model.interface";
import { FormControl } from "@angular/forms";
import { Router } from "@angular/router";
import { Title } from "@angular/platform-browser";
import { Store } from '../../interfaces/store.interface';
import { SessionProvider } from '../../providers/session-provider';
import { AppProperties } from '../../app.properties';

//import '../assets/css/styles.css';

@Component({
    selector: 'storeusers',
    template: require('./storeusers.component.html'),
    styles: [require('../../../css/common.css'),
        require('./storeusers.component.css')]
})
export class StoreUsersComponent {
    public users: StoreUser[];
    private searchStr: string = '';
    private store:Store;
    private title = 'Felhasználók';
    private addMode:boolean = false;

    private countAll: number = 0;
    private countFiltered: number = 0;
    private orderBy:string = 'user.name';
    private backwards:boolean = false;

    private currentItem:StoreUser = {
        role: null,
        user: null,
        id: null,
        store:null
    };    
    private inProgress:boolean = false;
    private fieldsToValidate = ['roleId', 'userId'];  
    private formErrors:any = {};
    private searchInput = new FormControl();

    @ViewChild('maintopbar') maintopbar;
    @ViewChild('mainbottombar') mainbottombar;

    constructor(private storeUserProvider: StoreUserProvider, private sessionProvider:SessionProvider,
                private projectUsersEl:ElementRef,
                private router:Router,
                private titleProvider:Title,
                private appProperties:AppProperties) {
        titleProvider.setTitle(appProperties.NAME+' - '+this.title);                
        this.users = [];
    }

tsconfig.json:

{
  "compilerOptions": {
    "moduleResolution": "node",
    "target": "es5",
    "sourceMap": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "skipDefaultLibCheck": true,
    "lib": [ "es6", "dom" ],
    "types": [ "node" ]
  },
  "exclude": [ "bin", "node_modules" ],
  "atom": { "rewriteTsconfig": false }
}

0 个答案:

没有答案