Skip to content

Instantly share code, notes, and snippets.

@stephencroberts
Created May 23, 2015 05:09
Show Gist options
  • Save stephencroberts/e7161cfa73734462ca8a to your computer and use it in GitHub Desktop.
Save stephencroberts/e7161cfa73734462ca8a to your computer and use it in GitHub Desktop.
AngularJS dynamic models
'use strict'
data = ($injector) ->
init = ->
registerModels()
service = {}
registerModels = ->
window.appModels.forEach (model) ->
Object.defineProperty service, model,
{
value: $injector.get "model.#{model}"
configurable: false
enumerable: true
}
init()
return service
data.$inject = ['$injector']
angular
.module('app.data')
.factory('data', data)
'use strict'
window.appModels ||= []
window.appModels.push 'review'
getAll = -> ['hello']
ModelReview = ->
{
getAll: getAll
}
angular
.module('app.data')
.factory('model.review', ModelReview)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment