Last active
February 18, 2017 19:59
-
-
Save aeinbu/c24cd0cd58b8856d2112029a82b1c220 to your computer and use it in GitHub Desktop.
This file contains 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
const angular = require("angular"); | |
const _ = require("lodash"); | |
angular | |
.module("modulename") | |
.directive("componentBinder", function($compile, $parse) { | |
return { | |
restrict: "E", | |
scope: { | |
componentName: "<", | |
}, | |
link(scope, element, attrs, controller, trancludeFn) { | |
let transcludeAttrs = _(attrs).omitBy((v, k) => k[0] == "$").omit("componentName").value(); | |
let attrsString = Object.keys(transcludeAttrs).reduce((agg, k) => { | |
return agg + ` ${_.kebabCase(k)}="${transcludeAttrs[k]}"` | |
}, ""); | |
let createElement = $compile(`<${scope.componentName} ${attrsString}/>`); | |
element.append(createElement(scope.$parent)); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment