You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NavigationEntry.bindingContext of app.run() not bind to rootView #6835
Expected behavior Root View Text should appear. onLoaded method should be called.
To Reproduce
Just replace your app.ts with this:
import*asappfrom"tns-core-modules/application";import{parse}from"tns-core-modules/ui/builder";import{StackLayout}from"tns-core-modules/ui/layouts/stack-layout";import{Observable}from"tns-core-modules/data/observable";classRootLayoutViewModelextendsObservable{publicrootViewText="Root View Text";onLoaded(){console.log("RootLayoutViewModel.onLoaded()")}}constrootLayoutXml=`<StackLayout loaded="{{ onLoaded }}"><Label text="{{ rootViewText }}"/></StackLayout>`;constrootLayoutView=<StackLayout>parse(rootLayoutXml);constrootLayoutViewModel=newRootLayoutViewModel();app.run({bindingContext: rootLayoutViewModel,// <--------------- this is NOT do what expectedcreate: ()=>{// rootLayoutView.bindingContext = rootLayoutViewModel; // <---------- workaroundreturnrootLayoutView;}});
changed the title [-]NavigationEntry.bindingContext not binded do dynamically created view[/-][+]NavigationEntry.bindingContext of app.run() not bind to rootView[/+]on Jan 27, 2019
Hi @webleaf,
Can you provide some more info about your use case(Why you need to set up the bindingContext on run) and what you are trying to achieve as a final result?
@tsonevn use case same as with using bindingContext in navigate()
I use one ViewModel per page. It's not comfortable to me to have 3 files (xml, code-behind and view-model). Also it is not comfortable to me to store view in xml file. I need to store view as string.
So there is no sense for me to use code-behind, because all I do in it is set bindindContext. All other things I do in ViewModel.
By the way, same concerns modal windows, where it is generally not possible to specify bindingContext in showModal()
Finally, app.run() have NavigationEntry as attribute, so it should work.
@webleaf the thing is that with application.run your root view should be Frame so the binding context is passed to the Frame and no to your initial page.
If you want to start the app directly from a page (that would mean SPA app) you can use the start method
Apart from that if you want to have a Frame and more complex navigation scenarios then use the run and create a frame as root. The pass the binding context when you are creating the pages.
@NickIliev you are not right. With application.run your root view CAN BE any View NOT ONLY Frame. Vice versa, start method implicitly create Frame. I don't need such root Frame, because I use RadSideDrawer as root view.
Note: Prior to version 4.0.0 all NativeScript application had single topmost Frame implicitly created by the application.start() method. With NativeScript 4.x.x and above the root Frame is no longer implicitly created. Instead you can specify any View to be the root of your application while using application.run({ moduleName: "app-root"}) where app-root is the file containing your root View.
Activity
[-]NavigationEntry.bindingContext not binded do dynamically created view[/-][+]NavigationEntry.bindingContext of app.run() not bind to rootView[/+]tsonevn commentedon Jan 29, 2019
Hi @webleaf,
Can you provide some more info about your use case(Why you need to set up the bindingContext on
run) and what you are trying to achieve as a final result?Thank you in advance for your cooperation.
webleaf commentedon Jan 29, 2019
@tsonevn use case same as with using
bindingContextinnavigate()I use one
ViewModelper page. It's not comfortable to me to have 3 files (xml,code-behindandview-model). Also it is not comfortable to me to store view inxmlfile. I need to store view as string.So there is no sense for me to use code-behind, because all I do in it is set
bindindContext. All other things I do in ViewModel.By the way, same concerns modal windows, where it is generally not possible to specify
bindingContextinshowModal()Finally,
app.run()haveNavigationEntryas attribute, so it should work.webleaf commentedon Feb 7, 2019
@tsonevn I gave you more info. What's next?
NickIliev commentedon Feb 20, 2019
@webleaf the thing is that with
application.runyour root view should beFrameso the binding context is passed to theFrameand no to your initial page.If you want to start the app directly from a page (that would mean SPA app) you can use the start
methodUsing the
startmethod with binding contextApart from that if you want to have a
Frameand more complex navigation scenarios then use therunand create a frame as root. The pass the binding context when you are creating the pages.webleaf commentedon Feb 20, 2019
@NickIliev you are not right. With
application.runyour root view CAN BE anyViewNOT ONLYFrame. Vice versa,startmethod implicitly createFrame. I don't need such rootFrame, because I useRadSideDraweras root view.Note from here: https://docs.nativescript.org/core-concepts/application-lifecycle#application-run