angularjs - Ionic - Typescript error - Type is not an array or a string -


i starting ionic , angular , facing issue variable type. querying api ouput array of elements.

import { component } '@angular/core'; import { navcontroller } 'ionic-angular'; import  {postservice } '../_providers/post-service';  @component({   selector: 'page-home',   templateurl: 'home.html',   providers:[postservice] }) export class homepage {   public posts: any;   private start:number=0;    constructor(public navctrl: navcontroller, public postservice: postservice) {     this.getpost();   }   getpost(){     return new promise(       resolve => {         this.postservice.load(this.start)         .then(data => {           console.log(data);           for(let post of data) {             this.posts.push(post);           }           resolve(true);         });       }); }    doinfinite(infinitescroll:any) {    console.log(this.start);    this.start+=10;    this.getpost().then(()=>{        infinitescroll.complete();      });  }    likepost(post){     post.likes++;   }  } 

line 23, have issue: issue

and console.log returns: console.log

finally, postservice class looks this:

import { injectable } '@angular/core'; import { http } '@angular/http'; import 'rxjs/add/operator/map';  @injectable() export class postservice {    perpage:number = 10;    constructor(public http: http) {}    load(start:number=0) {      return new promise(resolve => {        this.http.get('http://api.voyonsvoir.fr/?[limit]='+this.perpage+'&filter[skip]='+start)         .map(res => res.json())         .subscribe(data => {           resolve(data.posts);          });     });   } } 

thanks help.

you need add types, both here:

public posts: any[] = []; 

and return service method:

load(start:number=0): promise<any[]> {     return new promise<any[]>(resolve => { 

note: better more specific any, should @ least running.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -