Recently I am trying to learn AngularJs and CoffeeScript by writing a small application.
After reading some blogs, I can write an Angular controller and a service with the CoffeeScript Class. The following is an example of a controller.
libr = angular.module('libr.controllers.main', [])
class MainController
@$inject: ['$scope']
constructor: (@$scope) ->
@$scope.test = test
test: ()->
console.log 'Hello'
libr.controller 'MainCtrl', MainController
And it works well.
But I can not convert Angular factory so successfully using the Coffee Class style.
var app = angular.module('app', ['ngResource', 'ngRoute']);
app.factory('Notes', ['$resource', function($resource) {
return $resource('/notes/:id', null,
{
'update': { method:'PUT' }
});
}]);
This code is an example of code on the official AngularJs website: http://docs.angularjs.org/api/ngResource.$resource
Can someone help me convert it to a CoffeeScript class style?
source
share