Created
March 6, 2015 11:44
-
-
Save danharper/6d7bf19b6c081ff7cc0a to your computer and use it in GitHub Desktop.
ngDirective - note I haven't exactly dove deep into directives, so I'm sure there are other forms this doesn't account for (e.g. only having the link method?)
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
import ngInject from './ngInject' | |
export default function ngDirective(directive) { | |
let func = function(...injectedArgs) { | |
let link = (...directiveArgs) => new directive(...injectedArgs, ...directiveArgs) | |
return {...directive.ddo(), link} | |
} | |
func.$inject = ngInject(directive).$inject | |
return func | |
} |
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
class InspectionCardDirective { | |
static ngInject() { | |
return ['fooService'] | |
} | |
static ddo() { | |
return { | |
retrict: 'E', | |
templateUrl: 'some/path.html', | |
scope: { | |
inspection: '=inspection' | |
} | |
} | |
} | |
constructor(fooService, scope, element, attrs) { | |
// my args are: | |
// injected args from ngInject | |
// followed by args for the link function (scope, element, attrs, ...etc) | |
} | |
} | |
// then when registering: | |
.directive('inspectionCard', ngDirective(InspectionCardDirective)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment