LoginSignup
2
3

More than 5 years have passed since last update.

AngularJSのFactoryとServiceをCoffeeScriptのclassを使って書く

Posted at

AngularJSのFactoryとServiceをCoffeeScriptのclassを使うとこう書ける。

# factory
angular.module('myApp').factory 'HogeFactory', [
  '$injection'
  ($injection) ->
    class HogeFactory
      constructor: ->

    {
      create: -> new HogeFactory
    }
]
# service
angular.module('myApp').service 'FugaService', [
  '$injection'
  class FugaService
    constructor: ($injection) ->
]
  • Factory: インスタンスを生産する機能を持ったオブジェクト
  • Service: インスタンス

というかんじでFactoryとServiceの違いを理解しやすくなる気がしている。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3