This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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)
- Loading branch information
Showing
3 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
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
32 changes: 32 additions & 0 deletions
32
src/adhocracy/adhocracy/frontend/static/js/Packages/Inject/Inject.ts
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
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(); | ||
}); | ||
}); | ||
} | ||
}; | ||
}; |
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