I have a AngularJS-based frontend using restangular to get objects. In DB one table stores Users and reference to selected language (languageId), and other contains Languages.
My problem is that everytime I try to open view to edit my User I am getting an error: TypeError: Cannot read property 'parentResource' of undefined, which does not happen when I try editing user with no language selected (null in language in Users table).
Interesting is that when I look into network tab in my browser console there is all the data needed in the response: userId, login, firstName, lastName and _embedded which contains languageId and some links between tables.
in my user controller I am getting data:
var original = userRest;
where userRest is created in app.js:
.state('users.edit', {
(...)
resolve: {
userRest: function(Restangular, $stateParams) {
return Restangular.one('users', $stateParams.userId).get();
}
}
})
everything works if user has no specified language, but DB seems to be ok, all links between tables are correct, there are no problems with inserts/deletes/updates. So I think it may be because of the language data being embedded but still I cannot find a way to make it work.
Edit: Response language not null:
{"firstName":"Test","lastName":"User","login":"testUser","password":"ttt","lastLoginSuccess":null,"lastLoginError":null,"lastDevice":null,"createdBy":"testuser18","createdOn":{"date":"2014-07-21 08:00:00","timezone_type":3,"timezone":"Europe\/Berlin"},"updatedBy":null,"updatedOn":null,"active":true,"userId":139,"_embedded":{"language":{"languageId":"en_GB","_links":{"self":{"href":"http:\/\/host\/api\/languages\/en_GB"}}}},"_links":{"self":{"href":"http:\/\/host\/api\/users\/139"}}}
response with null language:
{"firstName":"Test","lastName":"User","login":"testUser","password":"ttt","lastLoginSuccess":null,"lastLoginError":null,"lastDevice":null,"createdBy":"testuser18","createdOn":{"date":"2014-07-21 08:00:00","timezone_type":3,"timezone":"Europe\/Berlin"},"updatedBy":null,"updatedOn":null,"active":true,"userId":139,"language":null,"_links":{"self":{"href":"http:\/\/host\/api\/users\/139"}}}
Controller:
app.controller('EditUserCtrl', ['$scope', 'Acl', 'User', '$rootScope', 'userRest', 'flash', '$q', 'Languages',
function($scope, Acl, User, $rootScope, userRest, flash, $q, Languages) {
$scope.availableLanguages = Languages.all;
var original = userRest;
console.info(original);
$scope.user = User.copy(original.data);
(...)