Angular2,将数据推入数组并调用方法问题?

时间:2017-07-20 06:24:03

标签: angular

这里的情况是,service.ts方法getMetadata(data)将数据作为输入并存储在数组metaData = []中。 要求是,当将数据推送到metaData = []时,请调用方法getdata(metaData)

如何实现?请帮忙

service.ts

public metaData = [];

getMetadata(data){
  console.log("data");
  this.metaData.push({data});
  /* when all pushing of data into metaData =[] is finished,
     then call a method getdata(metaData );*/

getdata(metaData );
}

getdata(metaData ){
  /*------------------------*/
}

abc.component.ts

let Json1 = {
   "viewBys":["usstate"];
}
this.dataService.getMetadata(Json1 );  //here sending "Json1 " as a parameter

bcd.component.ts

let Json2 = {
  "viewBys":["brand"];
}
this.dataService.getMetadata(Json2 );  //here sending "Json2 " as a parameter

cde.component.ts

let Json3 = {
  "viewBys":["uscity"];
}
this.dataService.getMetadata(Json3 );  //here sending "Json3 " as a parameter

0 个答案:

没有答案