Skip to content

Instantly share code, notes, and snippets.

@danharper
Created March 5, 2015 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danharper/406e53ec4e831ae6b809 to your computer and use it in GitHub Desktop.
Save danharper/406e53ec4e831ae6b809 to your computer and use it in GitHub Desktop.
ngInject - define injections as a static method in your class
// ngInject.js
function ngInject(func) {
if (func.ngInject)) {
func.$inject = func.ngInject()
}
return func
}
// Auth/LoginController.js
class LoginController {
static ngInject() {
return ['userSession']
}
constructor(userSession) {
this._userSession = userSession
}
}
// Auth/index.js (the angular module definition)
angular.module('app.auth')
.controller('LoginController', ngInject(LoginController))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment