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

Commit

Permalink
Fix: Add and use inject directive as drop-in for transclude
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
nidico committed Jul 31, 2014
1 parent 98e9c02 commit 3a516ce
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/adhocracy/adhocracy/frontend/static/js/Adhocracy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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]);

Expand Down
Original file line number Diff line number Diff line change
@@ -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();
});
});
}
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</div>
<ol class="listing-rows">
<li ng-repeat="element in elements track by $index">
<span ng-transclude></span>
<span data-inject="inject"></span>
</li>
</ol>
</div>

0 comments on commit 3a516ce

Please sign in to comment.