Ionic router run OnInit only first time.
I have an Ionic application. But OnInit only works once, so there is an alternative.
I have version 6.11.1 of Ionic.
OnInit is an angular lifecycle hook. Your objects are likely staying on the stack and are therefore simply re-rendered and thus not triggering onInit.
Since this is an ionic application you should look at using ionViewDidEnter.
https://ionicframework.com/docs/angular/lifecycle
Related
I implemented app localization for a flutter app. Everything is working fine. But there's one issue. In the load method of my AppLocalization class, I call methods that return Futures which initiate my translations.
Now while the load method is initiating my translations, the build method of my main page is called which completes the build with old localizables. If I go to another page and come back, the page get translated since the localizables would already have been initialized.
To prevent this, I need to either pause the build method of the page which I'm not sure how to. Or retrigger the build method at the end of the load function in my AppLocalization class. I cannot navigate to that page in the AppLocalization class since I don't have access to build context there.
Anyone has had a similar challenge in their projects?
ionic g page SomePage also creates some-page.module.ts file. How do I prevent it from doing it?
I use Ionic 4
In Ionic v3, it is possible to use `--no-module`` flag, to skip the creation of module.ts file.
Try execute:
ionic g page SomePage --no-module
Hope this helps!
We shouldn't delete module from a page.
Page in Ionic is ment to represent the whole view, because there is also a Component which might be just a part of the view. So it is very obvious now, that every Page should have its module (for lazy loading) and a route to it.
If we generate component, we see that neither - module nor route is created, so it makes perfect sense now.
I'm searching the web to find a solution to implement url routing in Ionic2, I can't seem to find a way to access a page using a URL.
Has it been implemented in Ionic 2?
Should the Angular 2 router be used? Does it work with Ionic 2?
I need to be able to get the physical url of a page within the web app; in order to be able to share it outside the web app.
Thank you,
I think you are looking for the Ionic service DeepLinker. That does not replace the FILO/NavController but provide a way to define and display specific views based on URLs.
In your main module add:
imports: [
IonicModule.forRoot(MyApp, {}, {
links: [
{ component: DetailPage, name: 'Detail', segment: 'detail/:userId' }
]
})
]
The full documentation here.
Also, if you also release your PWA on the AppStore/Play Store, you can use the native plugin Ionic Deeplinks.
Ionic 2 uses a pile FILO schema for routing with his NavController methods ( like push, pop, setRoot). And you don't need to use a sequence for it like you would do with a Routing system, like to access page 2 i need to go through page 0 and 1, you can just push(NewPage) and it will work, so it gives you a much better control over your application pages and how they interact.
I've never seen anyone talking about using it. If the NavController uses the Angular 2 routing in its background i don't know, will search for this, but the Ionic NavController is easy to use and works very good on most cases, the only case it doesn't support yet is passing parameters back within his pop() method, for this i use a modal and style it totally like a normal page. You can also use setRoot instead of pop to pass data like so.
this.navCtrl.setRoot(MyPage, this.Data);
For more information please see the ionic 2 documentation on navigation
I can't link my scss to components in ionic 2 using the standard angular 2 :
styleUrls: ['form.component.scss']
How is it done ?
Ionic2 can take a bit of learning curve as they've redone a lot of how Angular2 works, but once you get used to it it's really fantastic...
For adding scss to components it's super easy, you just throw it into the folder with your TS/html and the ionic build gulp process takes care of the rest for you. So just kill that line for styleUrls and you'll be all set.
It does; however, jack with css inheritance some so you'll want to be careful how you set it up.
Which is best way to use in protractor ?
var driver = browser.driver;
driver.get("URL")
or
browser.get("URL")
browser.manage().timeouts().implicitlyWait(browser.params.implicitWaitTime);
Currently I have used second approach to open URL and perform any browser action. Should I change everything like first approach or my approach is nice to go ahead ?
My two cents
If its a non angular application - go For browser.driver.get()
If not go for browser.get('')
browser.get understands the angular cycle and waits for the angular activity to finish
from documentation - API Documentation
Navigate to the given destination and loads mock modules before
Angular. Assumes that the page being loaded uses Angular. If you need
to access a page which does not have Angular on load, use the wrapped
webdriver directly.
If you are using browser.get() then you dont need a implicit wait and ideally you should avoid using it