Created
May 23, 2015 05:09
-
-
Save stephencroberts/e7161cfa73734462ca8a to your computer and use it in GitHub Desktop.
AngularJS dynamic models
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
'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) |
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
'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