Within my parent controller, UserEditCtrl
, I am trying to access a user object from a service and set a property to another variable in the child controller, EditUserCtrl
:
userMgmtSvc.user(scope.editUserId).then(function(data) {
this.user = data;
});
However, when attempting to assign this property, an error is thrown:
Cannot read property 'user' of undefined.
I am struggling with referencing objects that are set using this
. For example, trying to log the user object returns undefined:
console.log('user', this.user);
Here is a portion of the parent controller code:
(
function (app) {
'use strict';
app.controller('UserEditCtrl', ['$scope', '$http', 'userMgmtSvc', 'createUserSvc', 'authSvc', '$state', '$timeout', '$location', '_',
function (scope, http, userMgmtSvc, createUserSvc, authSvc, state, timeout, location, _) {
userMgmtSvc.user(scope.editUserId.id || sessionStorage.getItem('editUser')).then(function(data) {
this.user = data;
createUserSvc.states().then(function(data) {
this.states = data;
});
createUserSvc.countries().then(function(data) {
this.countries = data;
});
createUserSvc.roles().then(function(data) {
this.roles = data;
});
createUserSvc.insuranceGroups().then(function(data) {
this.insuranceGroups = data;
});
this.selectedRoles = this.user.roles;
});
}]);
}(window.app)
);