Closed NickIliev closed 7 years ago
From @zaszlo on June 30, 2017 9:54
By debugging I found out that this.page is not undefined, only this.page.android is and this is why on the login screen I don't get this error as there this.page is not used with .android. Now, what could be the reason for page.android to be undefined when developing only for android and android emulator otherwise renders the code as expected.
From @zaszlo on June 30, 2017 10:17
So got to this https://github.com/NativeScript/NativeScript/issues/3970 that says to don't use page.android in ngInit, instead call it in a function fired from the layout when it is loaded:
So beneath ngInit I put
public layoutLoaded(args){
console.log("layoutLoaded begin");
this.isAndroid = !!this.page.android;
}
and in groceries.component.html
<GridLayout #container
(loaded)="layoutLoaded($event)"
...
And now I get the same error between the two, don't know what is calling/causing it:
JS: ngOnInit begin
JS: ngOnInit end
JS: ERROR TypeError: Cannot set property 'page' of undefined
JS: ERROR CONTEXT [object Object]
JS: layoutLoaded begin
Also I find it strange that in the sample application the page.android would be called incorrectly, in the ngOnInit already.
@zaszlo you can overcome the whole this.page.android
issue by using the out-of-the-box properties in the platform module
isAndroid isAndroid: boolean Defined in platform/platform.d.ts:11 Gets a value indicating if the app is running on the Android platform.
isIOS isIOS: boolean Defined in platform/platform.d.ts:16 Gets a value indicating if the app is running on the iOS platform.
respectivly you can import them as follows:
import { isAndroid, isIOS } from "platform";
//and later..
if (isAndroid) {
// do the Android stuff
}
From the API reference here
You can also try to call this.page
using ngAfterViewInit
which will be triggered after ngOnInit
From @zaszlo on June 30, 2017 11:48
@NickIliev as I see with removing the this.page.android from the ngOnInit, the error message of Cannot set property 'page' of undefined doesn't come anymore from there, from the this.page.android but some other call that I can't see. From angular's part the ngOnInit is where it starts, and form the calls from the layout I guess that the layoutLoaded shoud be triggered first so I don't understand what produces the error message between the two:
JS: ngOnInit begin
JS: ngOnInit end
JS: ERROR TypeError: Cannot set property 'page' of undefined
JS: ERROR CONTEXT [object Object]
JS: layoutLoaded begin
It seems to me that it's not the this.page.android or not only that.
Also, I can't seem to stop in debug mode at the breakpoints, commented on https://stackoverflow.com/questions/42407703/visual-studio-code-wont-stop-at-breakpoint-in-nativescript-app
@zaszlo check if your layout page exists. You have several options from this point - you can debug the error (if using VSCode you can see this article about debugging) or you can compare your code with the code from the Groceries end branch.
As this repository is only for login issues, bugs and feature requests related to NativeScript framework itself and not for the Groceries tutorial I will move this issue to the Groceries repository, and we can continue this conversation there.
I have compared with the original files without getting from where my bug comes from. How to check if my layout page exists? I have the "groceries.component.html" that is the page's layout page right? I have qouted from its code already.
I have followed the articles and use VSCode but will not stop at breakpoints, once it did, I can't reproduce it :).. But this is another issue.
@zaszlo you can create a repository with the project up to this point (exclude node_modules and platforms folders) and share the link here so I can investigate the issue locally.
https://github.com/zaszlo/nativeSample here it is, but I guess you'll have to ignore somehow the api I have set it up with.
ok, I got it, it doesn't refer to ui/page but to another object's page property (filter).
From @zaszlo on June 30, 2017 8:32
details below:
I started with the {N} provided groceries sample application and incrementally modified it to make it use my api. In the process I must have done something wrong but can't figure it out where so that when I login and would get to the groceries list I get this error:
JS: ERROR TypeError: Cannot set property 'page' of undefined JS: ERROR CONTEXT [object Object]
This is interesting because in the login page the same ui/page is imported and called so I don't get it why on the groceries page this breaks.
Checked
I tried to find related issues here and on stackoverflow and comparing my code with the original sample but.. I couldn't figured it out.
Which platform(s) does your issue occur on?
Android
Please provide the following version numbers that your issue occurs with:
package.json
file of your project)Please tell us how to recreate the issue in as much detail as possible.
My VisualStudio doesn't show anything to be wrong in my code, so I don't know what I do wrong.
Is there code involved? If so, please share the minimal amount of code needed to recreate the problem.
I guess these settings could be affecting it.
groceries.module.ts
app.module.ts
package.json
vendor.ts
Copied from original issue: NativeScript/NativeScript#4482