Skip to content
This repository was archived by the owner on Jun 20, 2023. It is now read-only.

Commit 3a516ce

Browse files
committed
Fix: Add and use inject directive as drop-in for transclude
As Angular-1.2.18 fixed a bug with transclude scoping, we need to use a custom transclude directive (which we call inject). See upstream issue and especially the following: angular/angular.js#7874 (comment)
1 parent 98e9c02 commit 3a516ce

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

src/adhocracy/adhocracy/frontend/static/js/Adhocracy.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import AdhUser = require("./Packages/User/User");
1919
import AdhDone = require("./Packages/Done/Done");
2020
import AdhCrossWindowMessaging = require("./Packages/CrossWindowMessaging/CrossWindowMessaging");
2121
import AdhRecursionHelper = require("./Packages/RecursionHelper/RecursionHelper");
22+
import AdhInject = require("./Packages/Inject/Inject");
2223

2324
import Listing = require("./Packages/Listing/Listing");
2425
import DocumentWorkbench = require("./Packages/DocumentWorkbench/DocumentWorkbench");
@@ -77,6 +78,7 @@ export var init = (config) => {
7778
app.factory("adhDone", AdhDone.factory);
7879

7980
app.factory("recursionHelper", ["$compile", AdhRecursionHelper.factory]);
81+
app.directive("inject", AdhInject.factory);
8082
app.service("adhHttp", ["$http", "$q", AdhHttp.Service]);
8183
app.factory("adhWebSocket", ["Modernizr", "adhConfig", AdhWebSocket.factory]);
8284

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* This is a drop-in replacement for ng-transclude.
3+
*
4+
* While the included template in ng-transclude inherits the scope from the
5+
* controller context where it is defined, the inject directive will use the
6+
* scope from where it is used.
7+
*
8+
* Due to a scoping bug in Angular < 1.2.18 it was possible to use transclude
9+
* instead of inject to get similar results.
10+
*
11+
* The inject directive is directly taken from
12+
* https://github.com/angular/angular.js/issues/7874#issuecomment-47647528
13+
*/
14+
15+
export var factory = () => {
16+
return {
17+
link: ($scope, $element, $attrs, controller, $transclude) => {
18+
if (!$transclude) {
19+
throw "Illegal use of inject directive in the template! " +
20+
"No parent directive that requires a transclusion found.";
21+
}
22+
var innerScope = $scope.$new();
23+
$transclude(innerScope, (clone) => {
24+
$element.empty();
25+
$element.append(clone);
26+
$element.on("$destroy", () => {
27+
innerScope.$destroy();
28+
});
29+
});
30+
}
31+
};
32+
};

src/adhocracy/adhocracy/frontend/static/js/Packages/Listing/Listing.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</div>
1111
<ol class="listing-rows">
1212
<li ng-repeat="element in elements track by $index">
13-
<span ng-transclude></span>
13+
<span data-inject="inject"></span>
1414
</li>
1515
</ol>
1616
</div>

0 commit comments

Comments
 (0)