Skip to content

Instantly share code, notes, and snippets.

@clouddueling
Forked from pmanijak/index.html
Created April 10, 2013 01:25
Show Gist options
  • Save clouddueling/5351010 to your computer and use it in GitHub Desktop.
Save clouddueling/5351010 to your computer and use it in GitHub Desktop.

Revisions

  1. @pmanijak pmanijak created this gist Sep 2, 2012.
    39 changes: 39 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    <!doctype html>
    <html ng-app="project">
    <head>
    <title>Angular: Service example</title>
    <script src="http://code.angularjs.org/angular-1.0.1.js"></script>
    <script>
    var projectModule = angular.module('project',[]);

    projectModule.factory('theService', function() {
    return {
    thing : {
    x : 100
    }
    };
    });

    function FirstCtrl($scope, theService) {
    $scope.thing = theService.thing;
    $scope.name = "First Controller";
    }

    function SecondCtrl($scope, theService) {
    $scope.someThing = theService.thing;
    $scope.name = "Second Controller!";
    }
    </script>
    </head>
    <body>
    <div ng-controller="FirstCtrl">
    <h2>{{name}}</h2>
    <input ng-model="thing.x"/>
    </div>

    <div ng-controller="SecondCtrl">
    <h2>{{name}}</h2>
    <input ng-model="someThing.x"/>
    </div>
    </body>
    </html>