Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
  <meta name="description" content="Angular Avatar Example" />  
  <script src="//crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/md5.js"></script>
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
  <meta charset=utf-8 />
  <title>Angular module/directive</title>
</head>
  
<body ng-app="AngularApp">
  <h1>Here</h1>
  
  <div ng-controller="LoginController">
    LOGIN CONTROLLER: <div ng-bind="user.name"></div>
  </div>
  
  <div ng-controller="OtherController">
    OTHER CONTROLLER: <div ng-bind="user.name"></div>
  </div>
  
</body>
  
</html>
 
var app = angular.module("AngularApp", ['test']);
angular.module('test', [])
  .controller('LoginController', ['$scope', 'AuthFactory', function ($scope, AuthFactory) {
    $scope.user = AuthFactory.user;
    
    AuthFactory.signin();
  }])
  .controller('OtherController', ['$scope', 'AuthFactory', function ($scope, AuthFactory) {
    $scope.user = AuthFactory.user;
  }])
.service('AuthFactory', ['$timeout', function($timeout) {
    var user = {};
  
    var signin = function() {
       console.log('signin');
       $timeout(function () { 
         user.name = 'TEST'; 
         console.log('user name set');
       }, 500);
    };
  
    return {
      signin: signin,
      user: user
    };
}]);
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers