物业' params'类型'路由器'上不存在

时间:2017-04-03 04:07:37

标签: angular

我想将id从一个组件传递到另一个组件。我使用的是我在互联网上找到的使用params的示例代码。但是,当我尝试这种方法时,我收到了错误Property 'params' does not exist on type 'Router'.我已经将参数放入contsructor

以下是我的服务和我的组件。

service.ts

getDetails(id: number) {
    console.log(id);
    return this.http.get('http://localhost:8000/api/v1/viewtask/?process='+ id, {headers: this.getHeaders()})
    .map((res:Response) => res.json());
  }


component.ts



import { Component, OnInit, Injectable } from '@angular/core';
import { Router, Params } from '@angular/router';
import { OAuthService } from "angular-oauth2-oidc";
import { Http, Response, Headers } from '@angular/http';
import { JobService } from "../../../shared/job.service";
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/toPromise';

@Component({
  templateUrl: './process.component.html',
  providers: [ JobService ],

})


    export class ProcessComponent {

      private data : Object;
      navigated = false;

     constructor(private oauthService: OAuthService, private router: Router, private jobService: JobService, private param: Params) {

     }

        public getProcess(){

          this.router.params.forEach((params: Params) => { // <------  error params start here
          if (params['id'] !== undefined) {
            let id = +params['id'];
            this.navigated = true;
            this.jobService.getDetails(id).subscribe(
              data => {
              let i = 0;
              for (let i = 0; i < data.length; i++) {
                this.data = data;

          }
          },
          );
          }

    });
    }
    }

0 个答案:

没有答案