By default your HTTP requests with the $HTTPS service in Angular is not cached. By the setting some options, you can turn caching on.
/** * Created by Answer1215 on 12/15/2014.*/Angular.module (' App ', [' ngmaterial ']). Controller (' Mainctrl ',function(Bookmarksservice, bookmarkscachefactory) {varMainctrl = This; Mainctrl.bookmarks= []; Mainctrl.getbookmarks=function() {Bookmarksservice.getbookmarks (). Then (function(response) {Mainctrl.bookmarks=Response.data; }); } Mainctrl.removecache=function() {Bookmarkscachefactory.remove ('./data/bookmarks.json '); }}). Service (' Bookmarksservice ',function($http, bookmarkscachefactory) {varBookmarksservice = {}; Bookmarksservice.getbookmarks=function() { return$http. Get ('./data/bookmarks.json '), {cache:bookmarkscachefactory}); } returnBookmarksservice; }). Factory (' Bookmarkscachefactory ',function($cacheFactory) {return$cacheFactory (' Bookmarks '); });
<!DOCTYPE HTML><HTML><HeadLang= "en"> <MetaCharSet= "UTF-8"> <title></title> <Linkrel= "stylesheet"href= "//rawgit.com/angular/bower-material/master/angular-material.css"> <Linkrel= "stylesheet"href= "./bower_components/angular-material/themes/indigo-theme.css"> <Linkrel= "stylesheet"href= "./bower_components/angular-material/themes/teal-theme.css"></Head><BodyNg-app= "App"Ng-controller= "Mainctrl as main" > <md-content> < SectionLayout= "column"layout-align= "Start Start"> <Divng-repeat= "B in Main.bookmarks">{{B.title}}</Div> </ Section> </md-content> <Md-buttonNg-click= "Main.getbookmarks ()"class= "Md-primary md-raised"Md-theme= "Indigo">Load Bookmarks</Md-button> <Md-buttonNg-click= "Main.removecache ()"class= "Md-primary md-raised"Md-theme= "Teal">Clear Cache</Md-button> <!--Angular Material Dependencies - <Scriptsrc= "//cdn.jsdelivr.net/hammerjs/2.0.4/hammer.js"></Script> <Scriptsrc= "//ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular.js"></Script> <Scriptsrc= "//ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular-animate.js"></Script> <Scriptsrc= "//ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular-aria.js"></Script> <!--Angular Material Javascript using Rawgit to load directly from ' Bower-material/master ' - <Scriptsrc= "//rawgit.com/angular/bower-material/master/angular-material.js"></Script> <Scriptsrc= "App.js"></Script></Body></HTML>
"Load bookmarks" only work for the first time clicking the button and Load the data.
After click "Clear Cache" and then'll load data again.
[AngularJS] $http Cache