问题
In addTo.component.ts component I have a method and constructor as follows
Method:
**addTo(ServicePlanId, basketSection) {......}**
Constructor:
**constructor(
private route: ActivatedRoute,
private router: Router,
private addToService: addToService,
private DashboardService: DashboardService) { })**
Imports:
import { Component, OnInit, Input, Output, EventEmitter,AfterViewInit} from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import {addToService} from './../services/addTo.service';
import {DashboardService} from './../../roles/services/dashboard.service';
Now I'm trying to call the addTo method in another component called dashboard.component as follows
imports of dashboard.component.ts
import {Router, ActivatedRoute} from '@angular/router';
import {DashboardService} from './../services/dashboard.service';
import {addToService} from './../../addToCart/services/addTo.service';
When I'm trying to creating the object for the addTo.component.ts throws below
**[0] app/modules/roles/components/dashboard.component.ts(87,33): error TS2345: Argument of type 'typeof ActivatedRoute' is not assignable to parameter of type 'ActivatedRoute'.
[0] Property 'url' is missing in type 'typeof ActivatedRoute'.**
**export class DashboardRole implements AfterViewInit {
......
......
addToComp = new addToComponent(ActivatedRoute, Router, addToService, DashboardService);
}**
Anyone suggest me how to resolve this error, suggest me if anything wrong in my code.
来源:https://stackoverflow.com/questions/41842603/how-to-call-another-components-methods-in-angular2