Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property 'foo' of null #14

Open
hoppities opened this issue Sep 29, 2015 · 9 comments
Open

Cannot read property 'foo' of null #14

hoppities opened this issue Sep 29, 2015 · 9 comments
Labels

Comments

@hoppities
Copy link

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;
      }
    };
@fmquaglia
Copy link
Owner

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

@hoppities
Copy link
Author

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?

@fmquaglia
Copy link
Owner

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.

@hoppities
Copy link
Author

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.

@fmquaglia
Copy link
Owner

Thanks @hoppities I appreciate it

@hoppities
Copy link
Author

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

@fmquaglia
Copy link
Owner

Thanks @hoppities can you share your test data?

@hoppities
Copy link
Author

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

@fmquaglia
Copy link
Owner

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":"someName@domain.com",
        "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":"someName@domain.com",
                "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":"someName@domain.com",
                "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":"abc@123.com",
                "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":"someName@domain.com",
        "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":"abc@123.com",
                "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":"abc@123.com",
                "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":"someName@domain.com",
        "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":"abc@123.com",
                "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":"someName@domain.com",
        "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":"abc@123.com",
                "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":"someName@domain.com",
        "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":"abc@123.com",
                "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":"someName@domain.com",
        "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":"abc@123.com",
                "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":"abc@123.com",
                "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":"someName@domain.com",
        "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":"someName@domain.com",
                "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":"someName@domain.com",
                "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":"someName@domain.com",
                "name":"John Doe",
                "lastLoggedIn":"0000-00-00 00:00:00",
                "pivot":{  
                    "patient_id":66,
                    "user_id":1
                }
            }
        ],
        "tags":[  

        ],
        "service":null
    }
]

Thanks @hoppities

@fmquaglia fmquaglia added the bug label Sep 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants