Skip to content

Instantly share code, notes, and snippets.

@whisher
Created August 10, 2013 14:03
Show Gist options
  • Save whisher/6200561 to your computer and use it in GitHub Desktop.
Save whisher/6200561 to your computer and use it in GitHub Desktop.
var app = angular.module( 'app', [] );
var MyFunc = function() {
this.name = "default name";
this.$get = function() {
this.name = "new name"
return "Hello from MyFunc.$get(). this.name = " + this.name;
};
return "Hello from MyFunc(). this.name = " + this.name;
};
// returns the actual function
app.service( 'myService', MyFunc );
// returns the function's return value
app.factory( 'myFactory', MyFunc );
// returns the output of the function's $get function
app.provider( 'myProv', MyFunc );
function MyCtrl( $scope, myService, myFactory, myProv ) {
$scope.serviceOutput = "myService = " + myService;
$scope.factoryOutput = "myFactory = " + myFactory;
$scope.providerOutput = "myProvider = " + myProv;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment