Skip to content

Instantly share code, notes, and snippets.

@sher
Created December 25, 2013 07:49
Show Gist options
  • Save sher/8121123 to your computer and use it in GitHub Desktop.
Save sher/8121123 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js"></script>
<meta name="description" content="Something" />
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body ng-app="app" ng-controller="AppCtrl">
<div ng-controller="MainCtrl">
<input type="text" ng-model='animal.name' /> {{ animal.name }}
<br />
<input type="text" ng-model='cow.name' /> {{ cow.name }}
</div>
</body>
</html>
app = angular.module('app', []);
app.controller('AppCtrl', function($rootScope){
});
app.controller('MainCtrl', function($scope, Animal, Cow){
$scope.animal = new Animal();
$scope.cow = new Cow();
});
app.provider('Animal', function(){
function Animal() {
this.name = "Animal";
}
Animal.prototype.constructor = Animal;
this.$get = function(){
return Animal;
};
});
app.provider('Cow', function(AnimalProvider){
function Cow() {
this.name = "Cow";
}
Animal = AnimalProvider.$get();
Cow.prototype = new Animal();
Cow.prototype.constructor = Cow;
this.$get = function(){
return Cow;
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment