ngOrderObjectBy icon indicating copy to clipboard operation
ngOrderObjectBy copied to clipboard

Cannot read property 'foo' of null

Open hoppities opened this issue 9 years ago • 9 comments

I'm using the setCriteria() function that is supposed to make it possible to order by children.

I have an object that has service has a child object. it just says cannot read property of null when I click. The rest of it works fine.

setCriteria('service.name')
$scope.criteria = 'id';
$scope.direction = true;
$scope.setCriteria = function(criteria) {
if ($scope.criteria === criteria) {
        $scope.direction = !$scope.direction;
      } else {
        $scope.criteria = criteria;
        $scope.direction  = false;
      }
    };

hoppities avatar Sep 29 '15 20:09 hoppities

@hoppities could you provide your test object, and may be a fiddle with a working example?

fmquaglia avatar Sep 29 '15 21:09 fmquaglia

I don't think this will help because this seems to work... http://plnkr.co/edit/TMUkn5ojtyV0LLojxBif?p=preview

I tested the json in my app as well, and it worked, so there must be something wrong with my object. I'm using Restangular. Does that matter?

hoppities avatar Sep 29 '15 23:09 hoppities

I couldn't tell you since I don't use Restangular at all. I use just plain resources and the $q service for promises with them.

May be you can test a vanilla resource and see if you can reproduce the problem with it.

fmquaglia avatar Sep 29 '15 23:09 fmquaglia

I have a hunch that it won't work if I have some objects that have null for service. I'll test and let you know.

hoppities avatar Sep 29 '15 23:09 hoppities

Thanks @hoppities I appreciate it

fmquaglia avatar Sep 29 '15 23:09 fmquaglia

That's it. If the child object is null, it fails.

hoppities avatar Sep 29 '15 23:09 hoppities

Thanks @hoppities can you share your test data?

fmquaglia avatar Sep 30 '15 00:09 fmquaglia

Here's a pastebin. It's set to expire in 1 day, so don't delay in copying the data :) http://pastebin.com/JUVNCfZM

hoppities avatar Sep 30 '15 00:09 hoppities

pastebin contents

[  
    {  
        "id":72,
        "created_at":"2015-09-08 13:36:58",
        "updated_at":"2015-09-24 14:51:57",
        "received":"2015-09-08",
        "category":"Fracture Care",
        "complainant_name":"Lana",
        "patientName":"Daniel",
        "dob":"2015-09-24T05:00:00.",
        "phone":5555555555,
        "email":"[email protected]",
        "complaint":"Something Terrible",
        "status":"unacknowledged",
        "creator":"Blane Damon",
        "editor":"John Doe",
        "notified":0,
        "service_id":2,
        "users":[  
            {  
                "id":1,
                "created_at":"2015-09-25 11:11:23",
                "updated_at":"2015-09-25 11:11:23",
                "email":"[email protected]",
                "name":"John Doe",
                "pivot":{  
                    "patient_id":72,
                    "user_id":1
                }
            },
            {  
                "id":2,
                "created_at":"2015-09-18 13:55:35",
                "updated_at":"2015-09-18 13:55:35",
                "email":"[email protected]",
                "name":"Jane Doe",
                "lastLoggedIn":"0000-00-00 00:00:00",
                "pivot":{  
                    "patient_id":72,
                    "user_id":2
                }
            },
            {  
                "id":9,
                "created_at":"2015-09-18 13:09:46",
                "updated_at":"2015-09-18 13:09:46",
                "email":"[email protected]",
                "name":"John Smith",
                "thumbnail":"/assets/img/default.png",
                "organizations":"null",
                "phone":null,
                "lastLoggedIn":"0000-00-00 00:00:00",
                "pivot":{  
                    "patient_id":72,
                    "user_id":9
                }
            }
        ],
        "tags":[  
            {  
                "id":21,
                "name":"Fracture Care",
                "created_at":"2015-09-24 10:01:53",
                "updated_at":"2015-09-24 10:01:53",
                "pivot":{  
                    "patient_id":72,
                    "tag_id":21
                }
            },
            {  
                "id":23,
                "name":"Call Center",
                "created_at":"2015-09-24 10:04:29",
                "updated_at":"2015-09-24 10:52:47",
                "pivot":{  
                    "patient_id":72,
                    "tag_id":23
                }
            }
        ],
        "service":{  
            "id":2,
            "name":"Sports Medicine",
            "created_at":"2015-09-24 08:13:43",
            "updated_at":"2015-09-24 08:13:43"
        }
    },
    {  
        "id":71,
        "created_at":"2015-09-08 13:35:17",
        "updated_at":"2015-09-29 12:26:42",
        "received":"2015-09-08",
        "category":"Fracture Care",
        "complainant_name":"Lana",
        "patientName":"Daniel",
        "dob":"2015-09-08T05:00:00.",
        "phone":5555555555,
        "email":"[email protected]",
        "complaint":"Something Terrible",
        "status":"",
        "creator":"",
        "editor":"John Doe",
        "notified":0,
        "service_id":7,
        "users":[  
            {  
                "id":11,
                "created_at":"2015-09-18 13:09:46",
                "updated_at":"2015-09-18 13:09:46",
                "email":"[email protected]",
                "name":"John Smith",
                "thumbnail":"/assets/img/default.png",
                "lastLoggedIn":"0000-00-00 00:00:00",
                "pivot":{  
                    "patient_id":71,
                    "user_id":11
                }
            },
            {  
                "id":10,
                "created_at":"2015-09-18 13:09:46",
                "updated_at":"2015-09-18 13:09:46",
                "email":"[email protected]",
                "name":"John Johnson",
                "thumbnail":"/assets/img/default.png",
                "lastLoggedIn":"0000-00-00 00:00:00",
                "pivot":{  
                    "patient_id":71,
                    "user_id":10
                }
            }
        ],
        "tags":[  
            {  
                "id":21,
                "name":"Fracture Care",
                "created_at":"2015-09-24 10:01:53",
                "updated_at":"2015-09-24 10:01:53",
                "pivot":{  
                    "patient_id":71,
                    "tag_id":21
                }
            }
        ],
        "service":{  
            "id":7,
            "name":"Upper Extremity",
            "created_at":"2015-09-24 10:04:37",
            "updated_at":"2015-09-24 10:04:37"
        }
    },
    {  
        "id":70,
        "created_at":"2015-09-08 13:33:47",
        "updated_at":"2015-09-29 18:51:39",
        "received":"2015-09-08",
        "category":"Fracture Care",
        "complainant_name":"Lana",
        "patientName":"Daniel",
        "dob":"2015-09-08T05:00:00.",
        "phone":5555555555,
        "email":"[email protected]",
        "complaint":"Something Terrible",
        "status":"",
        "creator":"",
        "editor":"John Doe",
        "notified":0,
        "service_id":1,
        "users":[  
            {  
                "id":9,
                "created_at":"2015-09-18 13:09:46",
                "updated_at":"2015-09-18 13:09:46",
                "email":"[email protected]",
                "name":"John Smith",
                "thumbnail":"/assets/img/default.png",
                "organizations":"null",
                "lastLoggedIn":"0000-00-00 00:00:00",
                "pivot":{  
                    "patient_id":70,
                    "user_id":9
                }
            }
        ],
        "tags":[  
            {  
                "id":21,
                "name":"Fracture Care",
                "created_at":"2015-09-24 10:01:53",
                "updated_at":"2015-09-24 10:01:53",
                "pivot":{  
                    "patient_id":70,
                    "tag_id":21
                }
            },
            {  
                "id":23,
                "name":"Call Center",
                "created_at":"2015-09-24 10:04:29",
                "updated_at":"2015-09-24 10:52:47",
                "pivot":{  
                    "patient_id":70,
                    "tag_id":23
                }
            }
        ],
        "service":{  
            "id":1,
            "name":"Ortho Express",
            "created_at":"2015-09-24 08:12:52",
            "updated_at":"2015-09-24 08:26:07"
        }
    },
    {  
        "id":69,
        "created_at":"2015-09-08 13:30:14",
        "updated_at":"2015-09-29 18:52:02",
        "received":"2015-09-08",
        "category":"Fracture Care",
        "complainant_name":"Lana",
        "patientName":"Daniel",
        "dob":"2015-09-08T05:00:00.",
        "phone":5555555555,
        "email":"[email protected]",
        "complaint":"Something Terrible",
        "status":"",
        "creator":"",
        "editor":"John Doe",
        "notified":0,
        "service_id":2,
        "users":[  
            {  
                "id":9,
                "created_at":"2015-09-18 13:09:46",
                "updated_at":"2015-09-18 13:09:46",
                "email":"[email protected]",
                "name":"John Smith",
                "thumbnail":"/assets/img/default.png",
                "organizations":"null",
                "phone":null,
                "lastLoggedIn":"0000-00-00 00:00:00",
                "pivot":{  
                    "patient_id":69,
                    "user_id":9
                }
            }
        ],
        "tags":[  
            {  
                "id":23,
                "name":"Call Center",
                "created_at":"2015-09-24 10:04:29",
                "updated_at":"2015-09-24 10:52:47",
                "pivot":{  
                    "patient_id":69,
                    "tag_id":23
                }
            }
        ],
        "service":{  
            "id":2,
            "name":"Sports Medicine",
            "created_at":"2015-09-24 08:13:43",
            "updated_at":"2015-09-24 08:13:43"
        }
    },
    {  
        "id":68,
        "created_at":"2015-09-08 13:29:54",
        "updated_at":"2015-09-29 12:26:59",
        "received":"2015-09-08",
        "category":"Fracture Care",
        "complainant_name":"Lana",
        "patientName":"Daniel",
        "dob":"2015-09-08T05:00:00.",
        "phone":5555555555,
        "email":"[email protected]",
        "complaint":"Something Terrible",
        "status":"",
        "creator":"",
        "editor":"John Doe",
        "notified":0,
        "service_id":2,
        "users":[  
            {  
                "id":9,
                "created_at":"2015-09-18 13:09:46",
                "updated_at":"2015-09-18 13:09:46",
                "email":"[email protected]",
                "name":"John Smith",
                "thumbnail":"/assets/img/default.png",
                "organizations":"null",
                "phone":null,
                "lastLoggedIn":"0000-00-00 00:00:00",
                "pivot":{  
                    "patient_id":68,
                    "user_id":9
                }
            }
        ],
        "tags":[  
            {  
                "id":21,
                "name":"Fracture Care",
                "created_at":"2015-09-24 10:01:53",
                "updated_at":"2015-09-24 10:01:53",
                "pivot":{  
                    "patient_id":68,
                    "tag_id":21
                }
            }
        ],
        "service":{  
            "id":2,
            "name":"Sports Medicine",
            "created_at":"2015-09-24 08:13:43",
            "updated_at":"2015-09-24 08:13:43"
        }
    },
    {  
        "id":67,
        "created_at":"2015-09-08 13:29:13",
        "updated_at":"2015-09-29 12:25:58",
        "received":"2015-09-08",
        "category":"Fracture Care",
        "complainant_name":"Lana",
        "patientName":"Daniel",
        "dob":"2015-09-08T05:00:00.",
        "phone":5555555555,
        "email":"[email protected]",
        "complaint":"Something Terrible",
        "status":"",
        "creator":"",
        "editor":"John Doe",
        "notified":0,
        "service_id":2,
        "users":[  
            {  
                "id":9,
                "created_at":"2015-09-18 13:09:46",
                "updated_at":"2015-09-18 13:09:46",
                "email":"[email protected]",
                "name":"John Smith",
                "thumbnail":"/assets/img/default.png",
                "organizations":"null",
                "phone":null,
                "lastLoggedIn":"0000-00-00 00:00:00",
                "pivot":{  
                    "patient_id":67,
                    "user_id":9
                }
            },
            {  
                "id":10,
                "created_at":"2015-09-18 13:09:46",
                "updated_at":"2015-09-18 13:09:46",
                "email":"[email protected]",
                "name":"Jane Doe",
                "thumbnail":"/assets/img/default.png",
                "organizations":"null",
                "phone":null,
                "lastLoggedIn":"0000-00-00 00:00:00",
                "pivot":{  
                    "patient_id":67,
                    "user_id":10
                }
            }
        ],
        "tags":[  
            {  
                "id":23,
                "name":"Call Center",
                "created_at":"2015-09-24 10:04:29",
                "updated_at":"2015-09-24 10:52:47",
                "pivot":{  
                    "patient_id":67,
                    "tag_id":23
                }
            },
            {  
                "id":21,
                "name":"Fracture Care",
                "created_at":"2015-09-24 10:01:53",
                "updated_at":"2015-09-24 10:01:53",
                "pivot":{  
                    "patient_id":67,
                    "tag_id":21
                }
            }
        ],
        "service":{  
            "id":2,
            "name":"Sports Medicine",
            "created_at":"2015-09-24 08:13:43",
            "updated_at":"2015-09-24 08:13:43"
        }
    },
    {  
        "id":66,
        "created_at":"2015-09-07 16:07:40",
        "updated_at":"2015-09-19 18:53:39",
        "received":"2015-09-15",
        "category":"",
        "complainant_name":"",
        "patientName":"Daniel",
        "dob":"12-29-2008",
        "phone":5555555555,
        "email":"[email protected]",
        "complaint":"I hate everything about what you choose to be.",
        "status":"in-progress",
        "creator":"Blane Damon",
        "editor":"Blane Damon",
        "notified":0,
        "service_id":0,
        "users":[  
            {  
                "id":3,
                "created_at":"2015-09-21 08:35:59",
                "updated_at":"2015-09-18 14:03:29",
                "email":"[email protected]",
                "name":"Blane Damon",
                "organizations":"",
                "phone":"",
                "lastLoggedIn":"0000-00-00 00:00:00",
                "pivot":{  
                    "patient_id":66,
                    "user_id":3
                }
            },
            {  
                "id":2,
                "created_at":"2015-09-18 13:55:35",
                "updated_at":"2015-09-18 13:55:35",
                "email":"[email protected]",
                "name":"Jane Doe",
                "lastLoggedIn":"0000-00-00 00:00:00",
                "pivot":{  
                    "patient_id":66,
                    "user_id":2
                }
            },
            {  
                "id":1,
                "created_at":"2015-09-25 11:11:23",
                "updated_at":"2015-09-25 11:11:23",
                "email":"[email protected]",
                "name":"John Doe",
                "lastLoggedIn":"0000-00-00 00:00:00",
                "pivot":{  
                    "patient_id":66,
                    "user_id":1
                }
            }
        ],
        "tags":[  

        ],
        "service":null
    }
]

Thanks @hoppities

fmquaglia avatar Sep 30 '15 02:09 fmquaglia