Ionic Common Caching processing method

Source: Internet
Author: User

Some interesting requirements are encountered when implementing caching on Ionic applications. Ionic does not cache data

To implement this feature, there's a very simple way to do this in ionic is to add a cache-view= "false" to the template directly.

<ion-view cache-view= "false" view-title= "My title!" > .....
</ion-view>

In this way, we can easily implement this function. But the problem is, when we step back, the page is slow--because there is no cache.

Then try to find another way, such as:

$state. Go ($state. Current, {}, {reload:true});

or the following:

$window. Location.reload (True)

But you can't work as expected. Ionic does not cache when entering, rewind cache

Then he thought of a way to judge whether to retreat. If not, call the data:

$scope. $on ("$ionicView. Beforeenter", function () {
      function clearcachefordetailpage () {
        var history = $ Ionichistory.forwardview ();
        var islastviewcommentpages = history && history.statename && (history.statename = = ' Commentview ');
        if (!islastviewcommentpages) {
          init ();
        }
      }
      Clearcachefordetailpage ();
    })

That is, call the init () method at this time, and then clear the data on the first page:

  $scope. $on ("$ionicView. Beforeenter", function () {
    var clearhistoryforindexpage = function () {
      var history = $ Ionichistory.forwardview ();
      if (history && history.statename) {
        $ionicHistory. clearhistory ();
      }
    };
    Clearhistoryforindexpage ();
  });
clear angular Directive cache

Then came the interesting question that directive was cached, and that it was time to modify these directvie:

The practice is as follows:

 link:function (scope, element, Attrs) {function render (value) {//);
    Render ($scope. Value);
    Scope. $watch ("Value", function (value) {render (value);
 }); }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.