Ionic/Angular: Preload content before transition animation - angularjs

I have a page that shows a list of asynchronously fetched users using ng-repeat | orderby:'value' .
The problem is that the first time the page is displayed, I see the elements appearing and getting sorted.
How can I force Ionic to load my view before I navigate to it?

One option is to use a "resolve" on the route.
This can be done both with ui-router resolve or with ng-router.
The disadvantage of using a "resolve" is that your page won't load until the data is available, however in your situation seems like that data is necessary before getting to the page.

Related

How can I force angular binding to update the view

I am adding a "loading task" in my html so I can update some {{loading_task}} when I am going to some slow route or loading some data from remote so I can keep the user interface more informative about what the current task is about in the system.
In my controller, I am simply updating the $rootScope.loading_task with a string in order to achieve this.
In my html, I have just
<h3 ng-model="loading_task">{{loading_task}}</h3>
Say I have couple messages:
1. loading
2. configuring
3. calculating
When I ctrl + f5 the page, I can the see the message updated only once from loading to configuring. Configuring is loading a big JS file from remote in a callback. So it works. While calculating is doing a lot of DOM event triggering. This basically seems not working at all. I am thinking it might just have blocked the whole web page rendering sequence.
When I not fresh page, just normal explore routes, the loading message is not updated at all. Always, the first message "loading".
What is the right way to do such thing?

Use Angular Ui-router without any views or templates

I've used UI router in the past in single page applications and found it prefect for loading new views and syncing them with the URL. However, I now have a normal multi-page ecommerce site which uses Angular a lot on various pages. Including te search results page.
I need to use ui-router only on this page to do ajax paging. Basically the content is already loaded onto the page and I have an ng-repeat for the results. It's a very simple set up.
What I want to do is change the state/url when the user hits the next/previous buttons and watch the stateParams to look for the new page number, then manually reload the new results and re-bind the ng-repeat to show the new results. Obviously I could load new search results without using ui-router at all but I want the back button to work so that you can go back through the pages.
Now, as far as I can see none of this requires any ui-view tags, or templates or controllers. I simply want to update the URL when a button is clicked and watch for changes. Is this possible with UI-router and if it is then what routes (if any) do I put into $stateProvider config?
Any help would be greatly appreciated.

Loading controllers when navigating through screens

I'm currently using directives in my ionic app, there directives are normally bind to a angular controller. So my problem is, when I navigate through the app, my controllers are not loading (loads for the first time) and hence I cannot setup some initial values.
Following is an example
I navigate to users screen/page
users controller loads (When I check with Chrome dev tools)
I navigate to home screen
I navigate back to users screen
At this point I expect users controller to load again, to setup my initial values, but it's not happening
I'm not sure if this is the default behavior, or am I missing something?
if you are using nested states, parent.child1, parent.child2, parent only loads 1 for the entire hierarchy, changing from child1 to child 2 will not reload the parent controller, thats one of the pros of using ui-router.
also note that with ionic latest version they introduced view caching so, the controller is only instanciated once for each view, to prevent that you need to use
cache-view="false"
in your ion-view
http://ionicframework.com/docs/api/directive/ionNavView/

Angular.js: prevent view loading when browser loads for the first time?

How can I prevent route loading when I hit refresh or when I load the page for the first time?
My backend respond with a chunk of HTML when ajax request and the whole page when normal request. If a normal request was made, I don't want angular to made the same request all over again to retrieve the same page but with a chunk of html instead of the whole page when the page loads.
How can I configure this?
May be you can't do that.
If you don't want the page to blink when angular load the whole page again, you can use the resolve attribute in angular-route or angular-ui-router.
You know, if angular don't load the page again, it can't handle user click or something else.
I have wrote a blog about this, researching the same problem with you, but in chinese. In the last, I decide to use resolve.
My blog url is http://isay.me/2014/06/angular-prerender-seo-and-use-resolve-for-page-flicker.html
Maybe you can have a look or not :)

Loading views with angularJS

I saw in many websites like twitter.com when you navigate between views by clicking navigation bar menus, then views loaded only one time and the loading spinner appear only for the first time the view has been loaded. If you back to the view again,it loaded directly and the loading spinner does not appear again.
I wonder, how can i do something like that using AngularJS ?. I need any tutorials to help me doing this or put me on the road.
This is already a core part of angular. Have a read of the $templateCache documentation. Here is a simple excerpt:
The first time a template is used, it is loaded in the template cache for quick retrieval. You can load templates directly into the cache in a script tag, or by consuming the $templateCache service directly.
So when using something like ng-include to grab a remote template via a file, it will only be loaded once, and automatically placed into this cache and reused when necessary.
If instead you are wondering how you go about only reloading part of the page, then you need to look at ng-view (which is part of the basic route module), or ui-router for more complex hierarchical view layouts.

Resources