错误:(SystemJS)无法解析ActivatedRoute的所有参数:(?,?,?,?,?,?,?,?) [英] Error: (SystemJS) Can't resolve all parameters for ActivatedRoute: (?, ?, ?, ?, ?, ?, ?, ?)

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

问题描述

我试图将ActivatedRoute组件注入到我的组件中,以访问我正在编辑的对象的ID(或者找出没有ID参数的对象,创建了新对象).

I'm trying to inject ActivatedRoute component into my component to access the ID of the object I'm editing (or to find out, there's no ID param, new object is created).

我仅创建了该组件的模板,并且在加载开始页面(而不是要使用该组件的页面的事件)时,出现以下错误:

I've created only the template for the component, and when I load start page (not event the page with the component I want to use) I get the following error:

错误:(SystemJS)无法解析ActivatedRoute的所有参数:(?,?,?,?,?,?,?,?).

Error: (SystemJS) Can't resolve all parameters for ActivatedRoute: (?, ?, ?, ?, ?, ?, ?, ?).

这是我的代码:

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

import { ActivatedRoute} from "@angular/router";

@Component({
    selector: 'my-edit',
    templateUrl: './templates/my-edit.htm',
    providers: [ActivatedRoute]
})

export class MyEditComponent implements OnInit {

    constructor(private route : ActivatedRoute){
        console.log(route.params)
    }

    ngOnInit() : void {
    }

}

它基于AngularJS网站(Heroes)中示例的代码,我真的不明白这里出了什么问题……我不能将ActivatedRoute导入到Component中,或者我需要一些额外的东西才能导入它吗?

It's based on the code from example from AngularJS site (Heroes), and I really don't get where's the problem here... Can't I import ActivatedRoute into Component, or I need something extra to be able to import it?

我的路由配置是:

@NgModule({
  imports: [ RouterModule.forRoot(routes) ],
  exports: [ RouterModule ]
})
export class AppRoutingModule {}

其中routes是路线的集合,就像在角度示例中一样,AppRoutingModule是在app.module中导入的.

where routes are the collection of routes, just like in angular example, and AppRoutingModule is imported in app.module.

推荐答案

@Component()删除providers: [ActivatedRoute]无需这样做. RouterModule.forRoot()已经提供了所需的一切.

Remove providers: [ActivatedRoute] from @Component() there is no need for that. RouterModule.forRoot() already provides everything that is required.

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

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