How to call another components methods in angular2

↘锁芯ラ 提交于 2020-01-15 05:08:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!