2016-01-28 80 views
0

在这段代码中,我有两种方法告诉我的应用程序不缓存所有视图,选项A和B表示,你推荐哪一个,为什么?避免在IONIC上缓存页面

选项A:

.config(function ($ionicConfigProvider, $urlRouterProvider, $httpProvider) { 
    $ionicConfigProvider.backButton.icon('ion-chevron-left'); 
    $ionicConfigProvider.backButton.previousTitleText(false).text(' '); 

    $httpProvider.interceptors.push('httpInterceptor'); 
    $httpProvider.interceptors.push('authInterceptor'); 

    $ionicConfigProvider.views.maxCache(0); 
}) 

选项B:

.run(function ($ionicPlatform, $ionicConfig) { 
    $ionicPlatform.ready(function() { 
     // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard 
     // for form inputs) 
     $ionicConfig.views.maxCache(0); 

     if (window.cordova && window.cordova.plugins.Keyboard) { 
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
      cordova.plugins.Keyboard.disableScroll(true); 
     } 
     if (window.StatusBar) { 
      // org.apache.cordova.statusbar required 
      StatusBar.styleDefault(); 
     } 
    }); 
}) 

回答

0

IMO它优选是做所有的配置设置在离子/角应用程序的配置阶段,所以在你的例子选项A.

根据https://github.com/angular/angular.js/wiki/Understanding-Dependency-Injection

配置阶段是您可以根据需要设置任何提供程序的位置。 这也是设置指令,控制器,过滤器等设置 的地方。

运行阶段是Angular实际编译您的DOM并从您的应用程序启动 。

然而Ionic docs提两种方法有两种:

这些CONFIGS可以用$ ionicConfigProvider在你的应用程序的 配置阶段而改变。 此外,$ ionicConfig也可以 设置并在运行阶段和应用程序 本身获取配置值。

副词另外意味着第二个选项是残差。