角度2-无法解析组件的所有参数:(?) [英] Angular 2 - Can't resolve all parameters for component: (?)

查看:95
本文介绍了角度2-无法解析组件的所有参数:(?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我启动了Angular2应用,但自几天以来我遇到了一个问题!

I started an Angular2 app and I have an issue since days !

Can't resolve all parameters for HomeComponent: (?).(…) 

但是我的问题不是关于特定的提供程序:我尝试在HomeComponent构造函数中注入的所有内容都会返回该错误.没有关于该错误的类似问题可以解决我的情况,现在我花了很多时间寻找它,以至于找不到它.

But my issue is not about a particular provider : Everyting that I try to inject in my HomeComponent constructor return that error. No similars questions on that errors resolved my situation, and now I spent so much time looking for this that I can't find it.

App.moodule.ts:

App.moodule.ts :

  import { NgModule }      from '@angular/core';
  import { BrowserModule } from '@angular/platform-browser';
  import { RouterModule }   from '@angular/router';
  import { SimpleNotificationsModule } from 'angular2-notifications';

  // Controllers
  import { AppComponent }  from './app.component';
  import { HomeComponent }  from './components/home.component';

  // Service
  import { AuthService } from './services/auth.service';

  // Guards
  import { AuthGuard } from './guards/auth.guard';

  @NgModule({
    imports: [ 
        BrowserModule,
        RouterModule.forRoot([
        {
          path: '',
          component: HomeComponent,
          canActivate: [AuthGuard]
        }
      ]),
      SimpleNotificationsModule
    ],
    declarations: [ 
        AppComponent,
        HomeComponent
    ],
    providers: [
        AuthGuard,
      AuthService,
    ],
    bootstrap: [ AppComponent ]
  })

  export class AppModule { }

我的HomeComponent:

My HomeComponent :

import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';

import { NotificationsService } from 'angular2-notifications';

import { AuthService } from '../services/auth.service';

@Component({
    selector: 'home',
    templateUrl: '/templates/home.html'
})

export class HomeComponent implements OnInit 
{
    public test: boolean = false;

    constructor( 
        private _authService: AuthService
    ) {}

    ngOnInit()
    {
        this.test = true;
    }
}

我尝试导入的AuthService为空,并且正如我所说,我在HomeComponent中注入的每个提供程序都返回该错误.每个构造函数参数都会在错误中创建一个新的问号.让我知道是否需要更多代码,但我认为其余的问题(模板,systemjs.config.js ...)不是问题

The AuthService that I try to import is empty, and as I said every providers that I inject in HomeComponent return that error. Each constructor argument create a new question mark in the error. Let me know if you need more code, but I don't think the rest (templates, systemjs.config.js...) is the problem

推荐答案

确保您拥有

"emitDecoratorMetadata": true,

中的

.如果启用了此功能,则无需在功能参数中添加@Inject().

这篇关于角度2-无法解析组件的所有参数:(?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆