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);
}); }