Cannot read proberty

Good Morning,

I try to show a list of subjects on screen. For that I use:

<ion-list>
    <button ion-item *ngFor="let item of data" (click)="itemSelected(item)">
      <h2>{{item.subject}}</h2>
      <p>{{item.otherOwner.displayName}}</p>

    </button>
  </ion-list>

everything works fine, but I got one problem.

Some of my entries in the otherOwner don’t have a displayName.

in this example, I get a list with 8 entries and the last of them has no displayName…

So it loads my first 7 entries, and then i get the error…
I know where it comes from, but I don’t know to fix it, so that for the last entry there is simply no displayName showed.

<p>{{item.otherOwner.displayName==null? '' : item.otherOwner.displayName}}</p>

or if its just an empty string

<p>{{item.otherOwner.displayName==''?  '' : item.otherOwner.displayName}}</p>

First, thank you

but i still get the error.

7: {id: "1035978", type: "appointments",…}
   Relationships: {otherOwner: {data: {id: "1012463", type: "users"},…},…}
8: {id: "1037561", type: "appointments",…}
   Relationships: {otherOwner: {data: null, links:

maybe this helps a bit

please write me an exact error message

Runtime Error
Cannot read property 'displayName' of undefined
Stack
TypeError: Cannot read property 'displayName' of undefined
    at Object.eval [as updateRenderer] (ng:///AppModule/HomePage.ngfactory.js:72:53)
    at Object.debugUpdateRenderer [as updateRenderer] (http://localhost:8101/build/vendor.js:13204:21)
    at checkAndUpdateView (http://localhost:8101/build/vendor.js:12509:14)
    at callViewAction (http://localhost:8101/build/vendor.js:12867:21)
    at execEmbeddedViewsAction (http://localhost:8101/build/vendor.js:12825:17)
    at checkAndUpdateView (http://localhost:8101/build/vendor.js:12505:5)
    at callViewAction (http://localhost:8101/build/vendor.js:12867:21)
    at execComponentViewsAction (http://localhost:8101/build/vendor.js:12799:13)
    at checkAndUpdateView (http://localhost:8101/build/vendor.js:12510:5)
    at callViewAction (http://localhost:8101/build/vendor.js:12867:21)
Ionic Framework: 3.6.0
Ionic App Scripts: 2.1.3
Angular Core: 4.1.3
Angular Compiler CLI: 4.1.3
Node: 6.11.2
OS Platform: Windows 10
Navigator Platform: Win32
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60
<p>{{item.otherOwner.data==null? '' : item.otherOwner.displayName}}</p>

:weary:

Runtime Error
Cannot read property 'data' of undefined
Stack
TypeError: Cannot read property 'data' of undefined
    at Object.eval [as updateRenderer] (ng:///AppModule/HomePage.ngfactory.js:72:53)
    at Object.debugUpdateRenderer [as updateRenderer] (http://localhost:8101/build/vendor.js:13204:21)
    at checkAndUpdateView (http://localhost:8101/build/vendor.js:12509:14)
    at callViewAction (http://localhost:8101/build/vendor.js:12867:21)
    at execEmbeddedViewsAction (http://localhost:8101/build/vendor.js:12825:17)
    at checkAndUpdateView (http://localhost:8101/build/vendor.js:12505:5)
    at callViewAction (http://localhost:8101/build/vendor.js:12867:21)
    at execComponentViewsAction (http://localhost:8101/build/vendor.js:12799:13)
    at checkAndUpdateView (http://localhost:8101/build/vendor.js:12510:5)
    at callViewAction (http://localhost:8101/build/vendor.js:12867:21)
Ionic Framework: 3.6.0
Ionic App Scripts: 2.1.3
Angular Core: 4.1.3
Angular Compiler CLI: 4.1.3
Node: 6.11.2
OS Platform: Windows 10
Navigator Platform: Win32
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36

IMHO this is a design flaw. If the template is always expecting a displayName, the controller should always provide one.

yeah that’s right,

but I’m a trainee and can only use what I get provided, so I must find a way to make it work

<p>{{item.otherOwner==null? '' : item.otherOwner.displayName}}</p>
lol, so maybe this, or just show me the exact structure of this array

this is it >.<

thank you for your efforts

I am very leery of explicit comparisons to null. While I still strongly believe this should be done in the controller, if you insist on doing it in the template, use falsiness, not == null.