I am trying to use data I get from the server in my angular code.
To do this, I first receive the data in my HTML file with the following code:
<script type="text/javascript">
var __firstName= <%- JSON.stringify(givenName) %>;
</script>
Then, I inject it in a service in my .js file:
myApp.service('user', function() {
return givenName=function(){
var user = __firstName;
return user;
};
});
which I inject in my controller:
var myApp = angular.module('frontApp', []);
myApp.controller('teammateInviteCtrl', ['$scope', '$element', '$http', '$window', '$log', '$timeout', 'user', function ($scope, $element, $http, $window, $log, $timeout, user) {
$scope.account = {
given_name: user.givenName(),
family_name: '',
email: '',
password: '',
company: '',
phone: ''
};
//some code
}]);
But here I get an empty result for $scope.account.given_name. How can I fix this?
console.logto see where the data is being lost?