CollectionVariable.length throws error


My html file has below code

<ion-content padding>
    <button ion-item detail-push *ngFor="#resource of resources" (click)="DisplayDetails($event,resource)">
      <ion-thumbnail item-left>
        <img [src]="resource.imageUrl">
      <p> <b> {{}} </b> • {{resource.experience}} Years</p>
       <ion-icon name="arrow-forward" item-right></ion-icon>
   <ion-item text-wrap [hidden] = "resources.length > 0">
       <p>No resource found for selected location. Sorry for the inconvenience caused. Kindly search for other locations.</p>

Not sure why for resources.length , it throws error as below
Uncaught (in promise): EXCEPTION: TypeError: Cannot read property ‘length’ of undefined in [resources.length > 0

Please help.

Chance are, you’re not setting resources as an array before the request.

So you’d want to do something like

export class MyClass {}

public resources = [];

  // get data

So this way, you know for sure that the data structure is an array and should have the property of length.

Thank you for your reply.
I have set as array before calling and please notice that I am iterating in ngRepeat and it works but below line resources.length ddoesn’t work.

Two ion-contents? why not just one?

Tried with single but that did not work…and I am new to ionic and learning so…

What Ionic version are you using? There’s a chance your ngFor syntax is obsolete and breaking things.

I am using 2.0.0-beta.32

That’s Ionic CLI version, maximum version of Ionic is 2.0.0.beta.9