Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

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

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:

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

This is my code:

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 {
    }

}

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?

My routing configuration is:

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...