Ionic 2 RC1

Hi,

I have an app in ionic 2 RC0 version. After I updated my ionic to ionic 2 RC1 (checked with the blog post) I am getting the following error:
Property ‘items’ does not exist on type '{}'
I have a provider which fetches data from a server. The data returned is an object containing items, but I can no longer access it.

this.fetchService.load().then(data => {
console.log(data.items);
});

I can no longer use my data in my refresher, infiniteScroll, and my constructor.
I would really appreciate it if some here help me.

How is your load method in the fetchService implemented?
If you return a promise, you should “type” it with any:
return new Promise < any > (resolve => {

})

or you can use:
data[‘items’] instead of data.items :slight_smile:

@gregor_srdic thanks for your reply.
This is my provider function:

load() {
return new Promise(resolve => {
this.http.get(‘localhost/api’)
.map(res => res.json())
.subscribe((data) => {
this.fetechedData = data;
resolve(this.moreRecentNews);
},
(err)=>{
this.fetechedData = {status:‘failed’,message:‘Connection Failed’};
resolve(this.fetechedData);
});
});
}

All what you gotta do is add : any and it will be fine. So it would look like this:

this.fetchService.load().then((data: any) => {
  console.log(data.items);
});

I think if the fetchService.load() method has a defined return type of any … or of another object that has the items property, you will not get this error.

@ihadeed
Thanks that helped. This is the complete provider:

import { Injectable } from ‘@angular/core’;
import { Http } from ‘@angular/http’;
import ‘rxjs/add/operator/map’;
@Injectable()
export class FetchService {

fetchedData: any = null;
constructor(public http: Http) {
}
load() {
return new Promise(resolve => {
this.http.get(‘localhost/api’)
.map(res => res.json())
.subscribe((data) => {
this.fetechedData = data;
resolve(this.moreRecentNews);
},
(err)=>{
this.fetechedData = {status:‘failed’,message:‘Connection Failed’};
resolve(this.fetechedData);
});
});
}
}

I have defined fetchedData as type any and I have set it to null. Am I doing something wrong?

no it’s fine, null can be assigned to anything.

@ihadeed
Thanks again.
So the correct way is to add data:any like the following:
this.fetchService.load().then((data: any) => {
console.log(data.items);
});

Am I right?

Yeah that’s right :slight_smile:

@ihadeed
Thanks a lot. You really helped me A LOT! :wink: