使用激活路由进行数据路由

时间:2016-11-29 07:07:44

标签: angular routing ionic2

在此console.log(this.sorder)打印sorder来自另一个组件,但不能分配给this.filter={sort_order:this.sorder},它在我的模板中以双向绑定方式使用,如果部分它正在工作完美

   import {Component, ViewEncapsulation} from '@angular/core';
   import {Http,Response,Headers} from "@angular/http";
   import { ActivatedRoute } from '@angular/router';

    @Component({
    selector: 'basic-tables',
    encapsulation: ViewEncapsulation.None,
    styles: [require('./filter_add.scss')],
    template: require('./filter_add.html')
    })

    export class FilterAdd {
    public filter;
    public filter_data;
    public filter_added:boolean = false;
    private headers: Headers;
    public sorder:string;
    public fname:string;
    private addFilter_url = 'http://localhost:4545/api/addFilter';

    constructor(private http:Http,private route:ActivatedRoute) {
    route.params.subscribe(params => {
      this.sorder = params['sort_order'];
      this.fname = params['name'];
    });

    this.headers = new Headers();
    this.headers.append('Content-Type', 'application/json');
    this.headers.append('Accept', 'application/json');

    // the question is about this part of the code:
    if(this.sorder==undefined  && this.fname==undefined) {
      this.filter = {
        sort_order: '11',
        filter_group_name: '1234'
      }
    }
    else{
      console.log(this.sorder);
      this.filter = {
        sort_order: this.sorder,
        filter_group_name: this.fname
      }
    }

0 个答案:

没有答案