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

查看:21
本文介绍了错误:(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 导入到组件中,或者我需要一些额外的东西才能导入它吗?

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 是路由的集合,就像在 angular 示例中一样,并且 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天全站免登陆