mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
State templates are cached automatically, but you can optionally cache other templates.
```js
$ionicTemplateCahce('myNgIncludeTemplate.html');
```
Optionally disable all preemptive caching with the `$ionicConfigProvider` or individual states by setting `prefetchTemplate`
in the $state definition
```js
$ionicTemplateCahce('myNgIncludeTemplate.html');
```js
angular.module('myApp', ['ionic'])
.config(function($stateProvider, $ionicConfigProvider) {
// disable preemptive template caching globally
$ionicConfigProvider.prefetchTemplates(false);
// disable individual states
$stateProvider
.state('tabs', {
url: "/tab",
abstract: true,
prefetchTemplate: false,
templateUrl: "tabs-templates/tabs.html"
})
.state('tabs.home', {
url: "/home",
views: {
'home-tab': {
prefetchTemplate: false,
templateUrl: "tabs-templates/home.html",
controller: 'HomeTabCtrl'
}
}
});
});
```
38 lines
1.5 KiB
JavaScript
38 lines
1.5 KiB
JavaScript
describe('$ionicTemplateCache', function() {
|
|
beforeEach(module('ionic'));
|
|
|
|
beforeEach(inject(function($ionicTemplateCache, $templateCache) {
|
|
ionicTemplateCache = $ionicTemplateCache;
|
|
templateCache = $templateCache;
|
|
}));
|
|
|
|
it('should run during initial startup', function () {
|
|
var info = templateCache.info();
|
|
expect(info.size).toBe(0);
|
|
expect(ionicTemplateCache._runCount).toBe(1);
|
|
});
|
|
|
|
it('should run immediately after a new addition after initial run', inject(function ($templateCache, $httpBackend, $timeout) {
|
|
$httpBackend.whenGET("/test").respond([{hello:"world"}]);
|
|
ionicTemplateCache('/test');
|
|
$timeout.flush();
|
|
var info = templateCache.info();
|
|
expect(info.size).toBe(1);
|
|
expect(ionicTemplateCache._runCount).toBe(2);
|
|
}));
|
|
|
|
it('should cache 5 templates at a time', inject(function ($httpBackend, $timeout) {
|
|
$httpBackend.whenGET("/test1").respond([{hello:"world"}]);
|
|
$httpBackend.whenGET("/test2").respond([{hello:"world"}]);
|
|
$httpBackend.whenGET("/test3").respond([{hello:"world"}]);
|
|
$httpBackend.whenGET("/test4").respond([{hello:"world"}]);
|
|
$httpBackend.whenGET("/test5").respond([{hello:"world"}]);
|
|
$httpBackend.whenGET("/test6").respond([{hello:"world"}]);
|
|
$httpBackend.whenGET("/test7").respond([{hello:"world"}]);
|
|
ionicTemplateCache(['/test1','/test2','/test2','/test3','/test4','/test5','/test6','/test7']);
|
|
$timeout.flush();
|
|
var info = templateCache.info();
|
|
expect(info.size).toBe(7);
|
|
expect(ionicTemplateCache._runCount).toBe(3);
|
|
}));
|
|
}); |