Skip to content

Commit 19cbe4b

Browse files
author
Nedyalko Nikolov
committed
Merge pull request #260 from NativeScript/nnikolov/LoadedEventFix
Emit loaded event after attaching to.
2 parents e2e21a8 + d0faa4e commit 19cbe4b

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

Diff for: ng-sample/app/examples/navigation/router-outlet-test.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class FirstComponent { }
1818
directives: [ROUTER_DIRECTIVES, NS_ROUTER_DIRECTIVES],
1919
styleUrls: ["examples/navigation/router-outlet-test.css"],
2020
template: `
21-
<StackLayout>
21+
<StackLayout #secondStack (loaded)="onLoaded(secondStack)">
2222
<Label [text]="'Second component - ' + id" class="title"></Label>
2323
</StackLayout>`
2424
})
@@ -27,6 +27,10 @@ class SecondComponent {
2727
constructor(routeParams: RouteParams) {
2828
this.id = routeParams.get("id");
2929
}
30+
31+
onLoaded(args) {
32+
console.log("==========>>>>>>>>>>>>>SecondComponent loaded event with args: " + args);
33+
}
3034
}
3135

3236
@Component({
@@ -35,7 +39,7 @@ class SecondComponent {
3539
styleUrls: ["examples/navigation/router-outlet-test.css"],
3640
template: `
3741
<StackLayout>
38-
<StackLayout class="nav">
42+
<StackLayout #stack class="nav" (loaded)="onLoaded(stack)">
3943
<Button text="First" [nsRouterLink]="['First']"></Button>
4044
<Button text="GO(1)" [nsRouterLink]="['Second', { id: 1 }]"></Button>
4145
<Button text="GO(2)" [nsRouterLink]="['Second', { id: 2 }]"></Button>
@@ -50,4 +54,8 @@ class SecondComponent {
5054
{ path: '/first', component: FirstComponent, name: 'First', useAsDefault: true },
5155
{ path: '/second/:id', component: SecondComponent, name: 'Second' },
5256
])
53-
export class RouterOutletTest { }
57+
export class RouterOutletTest {
58+
onLoaded(args) {
59+
console.log("==========>>>>>>>>>>>>>RouterOutletTest loaded event with args: " + args);
60+
}
61+
}

Diff for: src/nativescript-angular/renderer.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,17 @@ export class NativeScriptRenderer extends Renderer {
216216

217217
public createText(parentElement: NgView, value: string): NgView {
218218
traceLog('NativeScriptRenderer.createText');
219-
return this.viewUtil.createText(value);;
219+
return this.viewUtil.createText(value);
220220
}
221221

222222
public listen(renderElement: NgView, eventName: string, callback: Function): Function {
223223
traceLog('NativeScriptRenderer.listen: ' + eventName);
224224
let zonedCallback = (<any>global).Zone.current.wrap(callback);
225225
renderElement.on(eventName, zonedCallback);
226+
if (eventName === View.loadedEvent && renderElement.isLoaded) {
227+
const notifyData = {eventName: View.loadedEvent, object: renderElement};
228+
zonedCallback(notifyData);
229+
}
226230
return () => renderElement.off(eventName, zonedCallback);
227231
}
228232

0 commit comments

Comments
 (0)