我正在尝试将ActivatedRoute组件注入到我的组件中以访问我正在编辑的对象的ID(或者找出,没有ID参数,创建了新对象).
我只为组件创建了模板,当我加载起始页面时(不是带有我想要使用的组件的页面的事件),我收到以下错误:
错误:(SystemJS)无法解析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 {
}
}
Run Code Online (Sandbox Code Playgroud)
它基于来自AngularJS网站(英雄)的示例中的代码,我真的不知道这里的问题...我不能将ActivatedRoute导入Component,或者我需要一些额外的东西才能导入它?
我的路由配置是:
@NgModule({
imports: [ RouterModule.forRoot(routes) ],
exports: [ RouterModule ]
})
export class AppRoutingModule {}
Run Code Online (Sandbox Code Playgroud)
routes路径集合在哪里,就像在角度示例中一样,并AppRoutingModule在app.module中导入.