The code is below. It is a mix of some of my code and some from the flatify
theme.
What I am trying to make happen:
1) Site presents with login
2) User enters correct credentials (FB login in this case)
3) After login, the Identity Controller in identity.js below updates a user
service with the login result returned name
4) The AppCtrl picks this change up and applies it to the div shown as the
very last snippet.
Hopefully someone will be able to see the err of my ways here. I have been
beating on this for hours....sigh
// app.js
angular
.module('app', [
'ngRoute',
'app.identity',
'app.globalDataService',
])
.controller('AppCtrl', AppCtrl);
AppCtrl.$inject = ['$scope', '$location', '$rootScope', '$route',
'$document', 'userService'];
function AppCtrl($scope, $location, $rootScope, $route, $document,
userService) {
var vm = this;
this.userName = userService.getUserName();
// The bit below never updates the value of the local var from the factory.
$scope.$watch(function() {return userService.getUserName()},
function(newData, oldData) {
if(newData === oldData) return;
this.userName = newData;
});
vm.main = {
brand: 'Company',
name: this.userName
};
};
// userdataservice.js
angular
.module('app.globalDataService', [])
.factory('userService', userService);
function userService (){
var userName = "Test";
var userServiceInstance = {
getUserName : getUserName,
setUserName : setUserName
};
return userServiceInstance;
function getUserName() {
return userName;
}
function setUserName(inUserName) {
userName = inUserName;
}
};
// identity.js
angular
.module('app.identity', [])
.controller('IdentityCtrl',
['$scope', '$location', '$rootScope', '$route', '$document',
'userService',
function($scope, $location, $rootScope, $route, $document, userService) {
// There is much code around a FB login that goes
here. This final step below works. The Service is updated correctly.
userService.setUserName ("ResultofSomeLoginActivity");
}
]);
// HTML Snippet
<div data-ng-controller="AppCtrl as vm">{{vm.main.name}}"></div>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.