如何在angular2中调用另一个组件方法

时间:2017-01-25 02:53:23

标签: angularjs components

在addTo.component.ts组件中,我有一个方法和构造函数,如下所示

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';

现在我试图在名为dashboard.component的另一个组件中调用addTo方法,如下所示

imports of dashboard.component.ts
import {Router, ActivatedRoute}       from '@angular/router';
import {DashboardService} from './../services/dashboard.service';
import {addToService} from './../../addToCart/services/addTo.service';

当我尝试为addTo.component.ts创建对象时,抛出

**[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);
}**

任何人都建议我如何解决此错误,建议我在我的代码中是否有任何错误。

0 个答案:

没有答案