Search code examples
jsonangulardataservice

Angular2 RC5: get json data from web service not working


I am trying to load data from data service but ID appears as type error

selectedModule(item: any) {
  this.module = item;
    console.log(this.module);
    this.dataService.getAny('/modules/get-by-module', "Id", '1')
        .then((module: IModuleBySector) => {
            const cust = JSON.stringify(module);
            this.moduleSelected = module;
            console.log(this.moduleSelected);
    });
 }

Solution

  • I believe you want to send ID to the server side code and want to get data whose ID=1. You should try this,

    selectedModule(item: any) {
      this.module = item;
        console.log(this.module);
        this.dataService.getAny('/modules/get-by-module?Id=1')
            .then((module: IModuleBySector) => {
                const cust = JSON.stringify(module);
                this.moduleSelected = module;
                console.log(this.moduleSelected);
        });
     }