Trying to access a variable from my service in my controller in AngularJS [duplicate]












0
















This question already has an answer here:




  • REST API Login Pattern

    3 answers




I want to get some info about the currently logged in user, I have stored the variable in currentUser but nothing appears when I try to access it from my controller



authentication.service.js:



(function () {
'use strict';

angular
.module('thinkster.authentication.services')
.factory('Authentication', Authentication);


Authentication.$inject = ['$cookies', '$http'];

/**
* @namespace Authentication
* @returns {Factory}
*/
function Authentication($cookies, $http) {
/**
* @name Authentication
* @desc The Factory to be returned
*/


var Authentication = {
login: login,
register: register,
getAuthenticatedAccount: getAuthenticatedAccount,
isAuthenticated: isAuthenticated,
setAuthenticatedAccount: setAuthenticatedAccount,
unauthenticate: unauthenticate,
currentUser: ''
};



return Authentication;

////////////////////


    /**
* @name register
* @desc Try to register a new user
* @param {string} username The username entered by the user
* @param {string} password The password entered by the user
* @param {string} email The email entered by the user
* @returns {Promise}
* @memberOf thinkster.authentication.services.Authentication
*/
function register(email, password, username) {
return $http.post('/api/v1/accounts/', {
username: username,
password: password,
email: email,
}).then(registerSuccessFn, registerErrorFn);

function registerSuccessFn(data ̶,̶ ̶s̶t̶a̶t̶u̶s̶,̶ ̶h̶e̶a̶d̶e̶r̶s̶,̶ ̶c̶o̶n̶f̶i̶g̶ ) {
Authentication.login(email, password)
};

function registerErrorFn(data ̶,̶ ̶s̶t̶a̶t̶u̶s̶,̶ ̶h̶e̶a̶d̶e̶r̶s̶,̶ ̶c̶o̶n̶f̶i̶g̶,) {
console.log(data)
}
}

function login(email, password){
return $http.post('/api/v1/auth/login/', {
email: email,
password: password
}).then(loginSuccessFn, loginErrorFn);

function loginSuccessFn(data ̶,̶ ̶s̶t̶a̶t̶u̶s̶,̶ ̶h̶e̶a̶d̶e̶r̶s̶,̶ ̶c̶o̶n̶f̶i̶g̶ ) {

Authentication.setAuthenticatedAccount(data.data);
// pass data through to dashboard controller
window.location = '/dashboard'

Authentication.currentUser += data.config.data.email
console.log(Authentication.currentUser)

}

function loginErrorFn(data, status, headers, config) {
console.error('Failed');
console.log(data)
}
}})();


dashboard.controller.js



//dashboard controller



(function() {
'use strict';

angular
.module('thinkster.authentication.controllers')
.controller('DashboardController', DashboardController);

DashboardController.inject = ['$location, $scope', 'Authentication'];

function DashboardController($location, $scope, Authentication){
var vm = this;
vm.user_info = user_info
//vm.user_info2 = user_info

function user_info() {
return Authentication.currentUser
}
}

})();


I'm attempting to update currentUser in the loginSuccessFn(), it updates successfully in the service. I can see that in the console, but not when I try to reference it in my controller. Thanks in advance










share|improve this question















marked as duplicate by georgeawg angularjs
Users with the  angularjs badge can single-handedly close angularjs questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 '18 at 18:12


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • you mean give you my own plunker?

    – Charles Smith
    Nov 22 '18 at 21:51






  • 1





    The dashboard controller immediately accesses Authentification.currentUser but the service only sets that variable after a response comes from the server.

    – georgeawg
    Nov 23 '18 at 0:59













  • Hey thanks for the reply, how would I fix that?

    – Charles Smith
    Nov 23 '18 at 5:21











  • I wonder if I'd have to obtain currentUser from my login controller because that way I could have it return the value in a promise

    – Charles Smith
    Nov 23 '18 at 5:36













  • The .then method returns an new promise that resolves to what is returned to the .then block. When a .then block omits a return statement, the function returns undefined. The derived promise will resolve as undefined. In addition a rejected promise will be converted to a fulfilled promise that resolves to undefined.

    – georgeawg
    Nov 23 '18 at 16:05
















0
















This question already has an answer here:




  • REST API Login Pattern

    3 answers




I want to get some info about the currently logged in user, I have stored the variable in currentUser but nothing appears when I try to access it from my controller



authentication.service.js:



(function () {
'use strict';

angular
.module('thinkster.authentication.services')
.factory('Authentication', Authentication);


Authentication.$inject = ['$cookies', '$http'];

/**
* @namespace Authentication
* @returns {Factory}
*/
function Authentication($cookies, $http) {
/**
* @name Authentication
* @desc The Factory to be returned
*/


var Authentication = {
login: login,
register: register,
getAuthenticatedAccount: getAuthenticatedAccount,
isAuthenticated: isAuthenticated,
setAuthenticatedAccount: setAuthenticatedAccount,
unauthenticate: unauthenticate,
currentUser: ''
};



return Authentication;

////////////////////


    /**
* @name register
* @desc Try to register a new user
* @param {string} username The username entered by the user
* @param {string} password The password entered by the user
* @param {string} email The email entered by the user
* @returns {Promise}
* @memberOf thinkster.authentication.services.Authentication
*/
function register(email, password, username) {
return $http.post('/api/v1/accounts/', {
username: username,
password: password,
email: email,
}).then(registerSuccessFn, registerErrorFn);

function registerSuccessFn(data ̶,̶ ̶s̶t̶a̶t̶u̶s̶,̶ ̶h̶e̶a̶d̶e̶r̶s̶,̶ ̶c̶o̶n̶f̶i̶g̶ ) {
Authentication.login(email, password)
};

function registerErrorFn(data ̶,̶ ̶s̶t̶a̶t̶u̶s̶,̶ ̶h̶e̶a̶d̶e̶r̶s̶,̶ ̶c̶o̶n̶f̶i̶g̶,) {
console.log(data)
}
}

function login(email, password){
return $http.post('/api/v1/auth/login/', {
email: email,
password: password
}).then(loginSuccessFn, loginErrorFn);

function loginSuccessFn(data ̶,̶ ̶s̶t̶a̶t̶u̶s̶,̶ ̶h̶e̶a̶d̶e̶r̶s̶,̶ ̶c̶o̶n̶f̶i̶g̶ ) {

Authentication.setAuthenticatedAccount(data.data);
// pass data through to dashboard controller
window.location = '/dashboard'

Authentication.currentUser += data.config.data.email
console.log(Authentication.currentUser)

}

function loginErrorFn(data, status, headers, config) {
console.error('Failed');
console.log(data)
}
}})();


dashboard.controller.js



//dashboard controller



(function() {
'use strict';

angular
.module('thinkster.authentication.controllers')
.controller('DashboardController', DashboardController);

DashboardController.inject = ['$location, $scope', 'Authentication'];

function DashboardController($location, $scope, Authentication){
var vm = this;
vm.user_info = user_info
//vm.user_info2 = user_info

function user_info() {
return Authentication.currentUser
}
}

})();


I'm attempting to update currentUser in the loginSuccessFn(), it updates successfully in the service. I can see that in the console, but not when I try to reference it in my controller. Thanks in advance










share|improve this question















marked as duplicate by georgeawg angularjs
Users with the  angularjs badge can single-handedly close angularjs questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 '18 at 18:12


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















  • you mean give you my own plunker?

    – Charles Smith
    Nov 22 '18 at 21:51






  • 1





    The dashboard controller immediately accesses Authentification.currentUser but the service only sets that variable after a response comes from the server.

    – georgeawg
    Nov 23 '18 at 0:59













  • Hey thanks for the reply, how would I fix that?

    – Charles Smith
    Nov 23 '18 at 5:21











  • I wonder if I'd have to obtain currentUser from my login controller because that way I could have it return the value in a promise

    – Charles Smith
    Nov 23 '18 at 5:36













  • The .then method returns an new promise that resolves to what is returned to the .then block. When a .then block omits a return statement, the function returns undefined. The derived promise will resolve as undefined. In addition a rejected promise will be converted to a fulfilled promise that resolves to undefined.

    – georgeawg
    Nov 23 '18 at 16:05














0












0








0









This question already has an answer here:




  • REST API Login Pattern

    3 answers




I want to get some info about the currently logged in user, I have stored the variable in currentUser but nothing appears when I try to access it from my controller



authentication.service.js:



(function () {
'use strict';

angular
.module('thinkster.authentication.services')
.factory('Authentication', Authentication);


Authentication.$inject = ['$cookies', '$http'];

/**
* @namespace Authentication
* @returns {Factory}
*/
function Authentication($cookies, $http) {
/**
* @name Authentication
* @desc The Factory to be returned
*/


var Authentication = {
login: login,
register: register,
getAuthenticatedAccount: getAuthenticatedAccount,
isAuthenticated: isAuthenticated,
setAuthenticatedAccount: setAuthenticatedAccount,
unauthenticate: unauthenticate,
currentUser: ''
};



return Authentication;

////////////////////


    /**
* @name register
* @desc Try to register a new user
* @param {string} username The username entered by the user
* @param {string} password The password entered by the user
* @param {string} email The email entered by the user
* @returns {Promise}
* @memberOf thinkster.authentication.services.Authentication
*/
function register(email, password, username) {
return $http.post('/api/v1/accounts/', {
username: username,
password: password,
email: email,
}).then(registerSuccessFn, registerErrorFn);

function registerSuccessFn(data ̶,̶ ̶s̶t̶a̶t̶u̶s̶,̶ ̶h̶e̶a̶d̶e̶r̶s̶,̶ ̶c̶o̶n̶f̶i̶g̶ ) {
Authentication.login(email, password)
};

function registerErrorFn(data ̶,̶ ̶s̶t̶a̶t̶u̶s̶,̶ ̶h̶e̶a̶d̶e̶r̶s̶,̶ ̶c̶o̶n̶f̶i̶g̶,) {
console.log(data)
}
}

function login(email, password){
return $http.post('/api/v1/auth/login/', {
email: email,
password: password
}).then(loginSuccessFn, loginErrorFn);

function loginSuccessFn(data ̶,̶ ̶s̶t̶a̶t̶u̶s̶,̶ ̶h̶e̶a̶d̶e̶r̶s̶,̶ ̶c̶o̶n̶f̶i̶g̶ ) {

Authentication.setAuthenticatedAccount(data.data);
// pass data through to dashboard controller
window.location = '/dashboard'

Authentication.currentUser += data.config.data.email
console.log(Authentication.currentUser)

}

function loginErrorFn(data, status, headers, config) {
console.error('Failed');
console.log(data)
}
}})();


dashboard.controller.js



//dashboard controller



(function() {
'use strict';

angular
.module('thinkster.authentication.controllers')
.controller('DashboardController', DashboardController);

DashboardController.inject = ['$location, $scope', 'Authentication'];

function DashboardController($location, $scope, Authentication){
var vm = this;
vm.user_info = user_info
//vm.user_info2 = user_info

function user_info() {
return Authentication.currentUser
}
}

})();


I'm attempting to update currentUser in the loginSuccessFn(), it updates successfully in the service. I can see that in the console, but not when I try to reference it in my controller. Thanks in advance










share|improve this question

















This question already has an answer here:




  • REST API Login Pattern

    3 answers




I want to get some info about the currently logged in user, I have stored the variable in currentUser but nothing appears when I try to access it from my controller



authentication.service.js:



(function () {
'use strict';

angular
.module('thinkster.authentication.services')
.factory('Authentication', Authentication);


Authentication.$inject = ['$cookies', '$http'];

/**
* @namespace Authentication
* @returns {Factory}
*/
function Authentication($cookies, $http) {
/**
* @name Authentication
* @desc The Factory to be returned
*/


var Authentication = {
login: login,
register: register,
getAuthenticatedAccount: getAuthenticatedAccount,
isAuthenticated: isAuthenticated,
setAuthenticatedAccount: setAuthenticatedAccount,
unauthenticate: unauthenticate,
currentUser: ''
};



return Authentication;

////////////////////


    /**
* @name register
* @desc Try to register a new user
* @param {string} username The username entered by the user
* @param {string} password The password entered by the user
* @param {string} email The email entered by the user
* @returns {Promise}
* @memberOf thinkster.authentication.services.Authentication
*/
function register(email, password, username) {
return $http.post('/api/v1/accounts/', {
username: username,
password: password,
email: email,
}).then(registerSuccessFn, registerErrorFn);

function registerSuccessFn(data ̶,̶ ̶s̶t̶a̶t̶u̶s̶,̶ ̶h̶e̶a̶d̶e̶r̶s̶,̶ ̶c̶o̶n̶f̶i̶g̶ ) {
Authentication.login(email, password)
};

function registerErrorFn(data ̶,̶ ̶s̶t̶a̶t̶u̶s̶,̶ ̶h̶e̶a̶d̶e̶r̶s̶,̶ ̶c̶o̶n̶f̶i̶g̶,) {
console.log(data)
}
}

function login(email, password){
return $http.post('/api/v1/auth/login/', {
email: email,
password: password
}).then(loginSuccessFn, loginErrorFn);

function loginSuccessFn(data ̶,̶ ̶s̶t̶a̶t̶u̶s̶,̶ ̶h̶e̶a̶d̶e̶r̶s̶,̶ ̶c̶o̶n̶f̶i̶g̶ ) {

Authentication.setAuthenticatedAccount(data.data);
// pass data through to dashboard controller
window.location = '/dashboard'

Authentication.currentUser += data.config.data.email
console.log(Authentication.currentUser)

}

function loginErrorFn(data, status, headers, config) {
console.error('Failed');
console.log(data)
}
}})();


dashboard.controller.js



//dashboard controller



(function() {
'use strict';

angular
.module('thinkster.authentication.controllers')
.controller('DashboardController', DashboardController);

DashboardController.inject = ['$location, $scope', 'Authentication'];

function DashboardController($location, $scope, Authentication){
var vm = this;
vm.user_info = user_info
//vm.user_info2 = user_info

function user_info() {
return Authentication.currentUser
}
}

})();


I'm attempting to update currentUser in the loginSuccessFn(), it updates successfully in the service. I can see that in the console, but not when I try to reference it in my controller. Thanks in advance





This question already has an answer here:




  • REST API Login Pattern

    3 answers








angularjs service controller






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 1:06









georgeawg

33.9k105270




33.9k105270










asked Nov 22 '18 at 21:15









Charles SmithCharles Smith

6621918




6621918




marked as duplicate by georgeawg angularjs
Users with the  angularjs badge can single-handedly close angularjs questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 '18 at 18:12


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by georgeawg angularjs
Users with the  angularjs badge can single-handedly close angularjs questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 23 '18 at 18:12


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • you mean give you my own plunker?

    – Charles Smith
    Nov 22 '18 at 21:51






  • 1





    The dashboard controller immediately accesses Authentification.currentUser but the service only sets that variable after a response comes from the server.

    – georgeawg
    Nov 23 '18 at 0:59













  • Hey thanks for the reply, how would I fix that?

    – Charles Smith
    Nov 23 '18 at 5:21











  • I wonder if I'd have to obtain currentUser from my login controller because that way I could have it return the value in a promise

    – Charles Smith
    Nov 23 '18 at 5:36













  • The .then method returns an new promise that resolves to what is returned to the .then block. When a .then block omits a return statement, the function returns undefined. The derived promise will resolve as undefined. In addition a rejected promise will be converted to a fulfilled promise that resolves to undefined.

    – georgeawg
    Nov 23 '18 at 16:05



















  • you mean give you my own plunker?

    – Charles Smith
    Nov 22 '18 at 21:51






  • 1





    The dashboard controller immediately accesses Authentification.currentUser but the service only sets that variable after a response comes from the server.

    – georgeawg
    Nov 23 '18 at 0:59













  • Hey thanks for the reply, how would I fix that?

    – Charles Smith
    Nov 23 '18 at 5:21











  • I wonder if I'd have to obtain currentUser from my login controller because that way I could have it return the value in a promise

    – Charles Smith
    Nov 23 '18 at 5:36













  • The .then method returns an new promise that resolves to what is returned to the .then block. When a .then block omits a return statement, the function returns undefined. The derived promise will resolve as undefined. In addition a rejected promise will be converted to a fulfilled promise that resolves to undefined.

    – georgeawg
    Nov 23 '18 at 16:05

















you mean give you my own plunker?

– Charles Smith
Nov 22 '18 at 21:51





you mean give you my own plunker?

– Charles Smith
Nov 22 '18 at 21:51




1




1





The dashboard controller immediately accesses Authentification.currentUser but the service only sets that variable after a response comes from the server.

– georgeawg
Nov 23 '18 at 0:59







The dashboard controller immediately accesses Authentification.currentUser but the service only sets that variable after a response comes from the server.

– georgeawg
Nov 23 '18 at 0:59















Hey thanks for the reply, how would I fix that?

– Charles Smith
Nov 23 '18 at 5:21





Hey thanks for the reply, how would I fix that?

– Charles Smith
Nov 23 '18 at 5:21













I wonder if I'd have to obtain currentUser from my login controller because that way I could have it return the value in a promise

– Charles Smith
Nov 23 '18 at 5:36







I wonder if I'd have to obtain currentUser from my login controller because that way I could have it return the value in a promise

– Charles Smith
Nov 23 '18 at 5:36















The .then method returns an new promise that resolves to what is returned to the .then block. When a .then block omits a return statement, the function returns undefined. The derived promise will resolve as undefined. In addition a rejected promise will be converted to a fulfilled promise that resolves to undefined.

– georgeawg
Nov 23 '18 at 16:05





The .then method returns an new promise that resolves to what is returned to the .then block. When a .then block omits a return statement, the function returns undefined. The derived promise will resolve as undefined. In addition a rejected promise will be converted to a fulfilled promise that resolves to undefined.

– georgeawg
Nov 23 '18 at 16:05












1 Answer
1






active

oldest

votes


















1














First why are you setting the variable using +=



(Authentication.currentUser += data.config.data.email)



Set the current user using =




  1. Authentication.currentUser = data.config.data


  2. Authentication.currentUser = data.config.data.email



Second user_info is a function so you have to call it, change



vm.user_info = user_info to vm.user_info = user_info()



Also I'd use camelCase for functions and under_score for object fields for readability and consistency



example



function userInfo() { // camelCase 
return Authentication.currentUser;
}

var vm = this
vm.user_info = userInfo() // under_score object





share|improve this answer
























  • Hey that isn't working either, I've tried both of those adjustments before. Is it because I'm retrieving currentUser before the request is made?

    – Charles Smith
    Nov 23 '18 at 5:22











  • Yeah that must be the issue, because when I hardcode a value for currentUser it works

    – Charles Smith
    Nov 23 '18 at 5:24






  • 1





    yea you have to set the value (finish the request and action) before retrieving the data point.

    – andrewoodleyjr
    Nov 23 '18 at 6:03











  • Okay how would I go about that? How do I retrieve the value after the request is made? with .then()?

    – Charles Smith
    Nov 23 '18 at 22:08


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














First why are you setting the variable using +=



(Authentication.currentUser += data.config.data.email)



Set the current user using =




  1. Authentication.currentUser = data.config.data


  2. Authentication.currentUser = data.config.data.email



Second user_info is a function so you have to call it, change



vm.user_info = user_info to vm.user_info = user_info()



Also I'd use camelCase for functions and under_score for object fields for readability and consistency



example



function userInfo() { // camelCase 
return Authentication.currentUser;
}

var vm = this
vm.user_info = userInfo() // under_score object





share|improve this answer
























  • Hey that isn't working either, I've tried both of those adjustments before. Is it because I'm retrieving currentUser before the request is made?

    – Charles Smith
    Nov 23 '18 at 5:22











  • Yeah that must be the issue, because when I hardcode a value for currentUser it works

    – Charles Smith
    Nov 23 '18 at 5:24






  • 1





    yea you have to set the value (finish the request and action) before retrieving the data point.

    – andrewoodleyjr
    Nov 23 '18 at 6:03











  • Okay how would I go about that? How do I retrieve the value after the request is made? with .then()?

    – Charles Smith
    Nov 23 '18 at 22:08
















1














First why are you setting the variable using +=



(Authentication.currentUser += data.config.data.email)



Set the current user using =




  1. Authentication.currentUser = data.config.data


  2. Authentication.currentUser = data.config.data.email



Second user_info is a function so you have to call it, change



vm.user_info = user_info to vm.user_info = user_info()



Also I'd use camelCase for functions and under_score for object fields for readability and consistency



example



function userInfo() { // camelCase 
return Authentication.currentUser;
}

var vm = this
vm.user_info = userInfo() // under_score object





share|improve this answer
























  • Hey that isn't working either, I've tried both of those adjustments before. Is it because I'm retrieving currentUser before the request is made?

    – Charles Smith
    Nov 23 '18 at 5:22











  • Yeah that must be the issue, because when I hardcode a value for currentUser it works

    – Charles Smith
    Nov 23 '18 at 5:24






  • 1





    yea you have to set the value (finish the request and action) before retrieving the data point.

    – andrewoodleyjr
    Nov 23 '18 at 6:03











  • Okay how would I go about that? How do I retrieve the value after the request is made? with .then()?

    – Charles Smith
    Nov 23 '18 at 22:08














1












1








1







First why are you setting the variable using +=



(Authentication.currentUser += data.config.data.email)



Set the current user using =




  1. Authentication.currentUser = data.config.data


  2. Authentication.currentUser = data.config.data.email



Second user_info is a function so you have to call it, change



vm.user_info = user_info to vm.user_info = user_info()



Also I'd use camelCase for functions and under_score for object fields for readability and consistency



example



function userInfo() { // camelCase 
return Authentication.currentUser;
}

var vm = this
vm.user_info = userInfo() // under_score object





share|improve this answer













First why are you setting the variable using +=



(Authentication.currentUser += data.config.data.email)



Set the current user using =




  1. Authentication.currentUser = data.config.data


  2. Authentication.currentUser = data.config.data.email



Second user_info is a function so you have to call it, change



vm.user_info = user_info to vm.user_info = user_info()



Also I'd use camelCase for functions and under_score for object fields for readability and consistency



example



function userInfo() { // camelCase 
return Authentication.currentUser;
}

var vm = this
vm.user_info = userInfo() // under_score object






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 23 '18 at 3:41









andrewoodleyjrandrewoodleyjr

2,19221417




2,19221417













  • Hey that isn't working either, I've tried both of those adjustments before. Is it because I'm retrieving currentUser before the request is made?

    – Charles Smith
    Nov 23 '18 at 5:22











  • Yeah that must be the issue, because when I hardcode a value for currentUser it works

    – Charles Smith
    Nov 23 '18 at 5:24






  • 1





    yea you have to set the value (finish the request and action) before retrieving the data point.

    – andrewoodleyjr
    Nov 23 '18 at 6:03











  • Okay how would I go about that? How do I retrieve the value after the request is made? with .then()?

    – Charles Smith
    Nov 23 '18 at 22:08



















  • Hey that isn't working either, I've tried both of those adjustments before. Is it because I'm retrieving currentUser before the request is made?

    – Charles Smith
    Nov 23 '18 at 5:22











  • Yeah that must be the issue, because when I hardcode a value for currentUser it works

    – Charles Smith
    Nov 23 '18 at 5:24






  • 1





    yea you have to set the value (finish the request and action) before retrieving the data point.

    – andrewoodleyjr
    Nov 23 '18 at 6:03











  • Okay how would I go about that? How do I retrieve the value after the request is made? with .then()?

    – Charles Smith
    Nov 23 '18 at 22:08

















Hey that isn't working either, I've tried both of those adjustments before. Is it because I'm retrieving currentUser before the request is made?

– Charles Smith
Nov 23 '18 at 5:22





Hey that isn't working either, I've tried both of those adjustments before. Is it because I'm retrieving currentUser before the request is made?

– Charles Smith
Nov 23 '18 at 5:22













Yeah that must be the issue, because when I hardcode a value for currentUser it works

– Charles Smith
Nov 23 '18 at 5:24





Yeah that must be the issue, because when I hardcode a value for currentUser it works

– Charles Smith
Nov 23 '18 at 5:24




1




1





yea you have to set the value (finish the request and action) before retrieving the data point.

– andrewoodleyjr
Nov 23 '18 at 6:03





yea you have to set the value (finish the request and action) before retrieving the data point.

– andrewoodleyjr
Nov 23 '18 at 6:03













Okay how would I go about that? How do I retrieve the value after the request is made? with .then()?

– Charles Smith
Nov 23 '18 at 22:08





Okay how would I go about that? How do I retrieve the value after the request is made? with .then()?

– Charles Smith
Nov 23 '18 at 22:08





Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy