diff --git a/src/adhocracy/adhocracy/frontend/static/js/Adhocracy.ts b/src/adhocracy/adhocracy/frontend/static/js/Adhocracy.ts index 531902210..a3ebb2121 100644 --- a/src/adhocracy/adhocracy/frontend/static/js/Adhocracy.ts +++ b/src/adhocracy/adhocracy/frontend/static/js/Adhocracy.ts @@ -19,6 +19,7 @@ import AdhUser = require("./Packages/User/User"); import AdhDone = require("./Packages/Done/Done"); import AdhCrossWindowMessaging = require("./Packages/CrossWindowMessaging/CrossWindowMessaging"); import AdhRecursionHelper = require("./Packages/RecursionHelper/RecursionHelper"); +import AdhInject = require("./Packages/Inject/Inject"); import Listing = require("./Packages/Listing/Listing"); import DocumentWorkbench = require("./Packages/DocumentWorkbench/DocumentWorkbench"); @@ -77,6 +78,7 @@ export var init = (config) => { app.factory("adhDone", AdhDone.factory); app.factory("recursionHelper", ["$compile", AdhRecursionHelper.factory]); + app.directive("inject", AdhInject.factory); app.service("adhHttp", ["$http", "$q", AdhHttp.Service]); app.factory("adhWebSocket", ["Modernizr", "adhConfig", AdhWebSocket.factory]); diff --git a/src/adhocracy/adhocracy/frontend/static/js/Packages/Inject/Inject.ts b/src/adhocracy/adhocracy/frontend/static/js/Packages/Inject/Inject.ts new file mode 100644 index 000000000..52a5701a2 --- /dev/null +++ b/src/adhocracy/adhocracy/frontend/static/js/Packages/Inject/Inject.ts @@ -0,0 +1,32 @@ +/** + * This is a drop-in replacement for ng-transclude. + * + * While the included template in ng-transclude inherits the scope from the + * controller context where it is defined, the inject directive will use the + * scope from where it is used. + * + * Due to a scoping bug in Angular < 1.2.18 it was possible to use transclude + * instead of inject to get similar results. + * + * The inject directive is directly taken from + * https://github.com/angular/angular.js/issues/7874#issuecomment-47647528 + */ + +export var factory = () => { + return { + link: ($scope, $element, $attrs, controller, $transclude) => { + if (!$transclude) { + throw "Illegal use of inject directive in the template! " + + "No parent directive that requires a transclusion found."; + } + var innerScope = $scope.$new(); + $transclude(innerScope, (clone) => { + $element.empty(); + $element.append(clone); + $element.on("$destroy", () => { + innerScope.$destroy(); + }); + }); + } + }; +}; diff --git a/src/adhocracy/adhocracy/frontend/static/js/Packages/Listing/Listing.html b/src/adhocracy/adhocracy/frontend/static/js/Packages/Listing/Listing.html index 2b5d38d92..673da9303 100644 --- a/src/adhocracy/adhocracy/frontend/static/js/Packages/Listing/Listing.html +++ b/src/adhocracy/adhocracy/frontend/static/js/Packages/Listing/Listing.html @@ -10,7 +10,7 @@
  1. - +