Skip to content

Commit b511cd0

Browse files
committed
Fix ngInclude event ordering
1 parent 8fd376f commit b511cd0

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/directive/include/include.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,9 @@ export function ngIncludeDirective(
8787
const thisChangeId = ++changeCounter;
8888

8989
if (src) {
90-
// set the 2nd param to true to ignore the template request error so that the inner
91-
// contents and scope can be cleaned up.
92-
await $templateRequest(src).then(
93-
(response) => {
90+
scope.$emit("$includeContentRequested", src);
91+
$templateRequest(src)
92+
.then((response) => {
9493
if (scope._destroyed) return;
9594

9695
if (thisChangeId !== changeCounter) return;
@@ -121,18 +120,16 @@ export function ngIncludeDirective(
121120
currentElement = clone;
122121
currentScope.$emit("$includeContentLoaded", src);
123122
scope.$eval(onloadExp);
124-
},
125-
(err) => {
123+
})
124+
.catch((err) => {
126125
if (scope._destroyed) return;
127126

128127
if (thisChangeId === changeCounter) {
129128
cleanupLastIncludeContent();
130129
scope.$emit("$includeContentError", src);
131130
}
132131
$exceptionHandler(new Error(err));
133-
},
134-
);
135-
scope.$emit("$includeContentRequested", src);
132+
});
136133
} else {
137134
cleanupLastIncludeContent();
138135
ctrl.template = null;

src/directive/include/include.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ describe("ngInclude", () => {
329329
}));
330330
EL.innerHTML = "<svg><test></test></svg>";
331331
angular.bootstrap(EL, ["myModule"]);
332-
getScope(EL).$on("$includeContentRequested", () => {
332+
getScope(EL).$on("$includeContentLoaded", () => {
333333
const child = EL.querySelectorAll("rect");
334334
expect(child.length).toBe(2);
335335
expect(child[0] instanceof SVGRectElement).toBe(true);

0 commit comments

Comments
 (0)