UNPKG

1.13 kBJavaScriptView Raw
1export var cjsSharedComponent = ["$compile", function($compile) {
2 return {
3 scope: true,
4 link: function(scope, element) {
5 // clean up the generated html a little
6 element.removeAttr("ng-repeat");
7 element.removeAttr("cjs-shared-component");
8
9 var cd = scope.componentDefinition;
10 // no need to create html elements when using the native implementation
11 if (cd.isNative && cd.isNative()) return;
12 element.addClass("sharedcomponent-" + cd.id);
13 var template = "";
14 template += "<div ng-controller=\"componentDefinition.ctrl\" >";
15 if (cd.template) {
16 template += cd.template;
17 } else if (cd.templateUrl) {
18 template += "<div ng-include src=\"componentDefinition.templateUrl\"></div>";
19 }
20 template += "</div>";
21
22 var newElement = angular.element(template);
23 $compile(newElement)(scope);
24 element.html("");
25 element.append(newElement);
26 }
27 };
28}];
29
30export default cjsSharedComponent;
\No newline at end of file