Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="https://rawgit.com/angular/bower-angular/master/angular.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body ng-app="app">
  
  <div ng-controller="control1">
    <h2>Controller #1</h2>
    <pre>{{teste}}</pre>
    <pre>{{teste2}}</pre>
  </div>
  
  <div ng-controller="control2">
    <h2>Controller #2</h2>
    <pre>{{teste}}</pre>
  </div>
  
</body>
</html>
 
angular.module('app', [])
.controller('control1', function($scope, shared) {
    shared.set('teste', {
        testecontroller1: "Apenas um teste"
    });
    $scope.teste = shared.get();
    $scope.teste2 = shared.get();
})
.controller('control2', function($scope, shared) {
    $scope.teste = shared.get('teste');
    shared.set('teste2', {
        testecontroller2: "Apenas um teste"
    });
    $scope.teste2 = shared.get('teste2');
})
.service('shared', [function() {
    var data = {};
    return {
        set: function(v, val) {
            data[v] = val;
        },
        get: function(v) {
            return (v)? data[v]: data;
        }
    };
}]);
Output

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

Dismiss x
public
Bin info
jorgtpro
0viewers