Created
August 15, 2013 05:58
-
-
Save anonymous/6238592 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyFunc | |
constructor: -> | |
@name = "default name" | |
return "Hello from MyFunc(). this.name = " + @name | |
$get: -> | |
@name = "new name" | |
"Hello from MyFunc.$get(). this.name = " + @name | |
app = angular.module("app", []) | |
app.service "myService", MyFunc | |
app.factory "myFactory", MyFunc | |
app.provider "myProv", MyFunc | |
MyCtrl = ($scope, myService, myFactory, myProv) -> | |
$scope.serviceOutput = "myService = " + myService | |
$scope.factoryOutput = "myFactory = " + myFactory | |
$scope.providerOutput = "myProvider = " + myProv |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html ng-app="app"> | |
<head> | |
<meta name="description" content="Simple Angular service, factory and provider; using CoffeeScript class" /> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.0.1/angular.min.js"></script> | |
<meta charset=utf-8 /> | |
<title>JS Bin</title> | |
</head> | |
<body ng-controller="MyCtrl"> | |
{{serviceOutput}} | |
<br/><br/> | |
{{factoryOutput}} | |
<br/><br/> | |
{{providerOutput}} | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This jsbin demonstrates how to use a CoffeeScript class to implement an Angular Service, using Service, Factory and Provider styles. You may have to click "Run with JS" to update Output pane. Details on my blog (http://blog.krnjevic.com)