我有我的app.js文件中的以下配置功能和運行功能。什麼是優化這些函數方法的最佳方法?我們可以將它們移動到單個配置功能中嗎? 或者我們可以將這些文件移動到另一個文件中,如果是,請更新我的代碼。如何優化AngularJS配置功能
.config(['cfpLoadingBarProvider', function(cfpLoadingBarProvider) {
cfpLoadingBarProvider.includeSpinner = false;
cfpLoadingBarProvider.includeBar = true;
}])
.run(function($state, $rootScope, $window) {
$rootScope.$state = $state;
$rootScope.$on("$locationChangeSuccess",
function(event, current, previous, rejection) {
$window.scrollTo(0, 0);
});
})
.config(function($httpProvider) {
return $httpProvider.interceptors.push("AuthInterceptor");
})
.config(['toastyConfigProvider', function(toastyConfigProvider) {
toastyConfigProvider.setConfig({
limit: 2,
sound: true,
position: 'top-center',
shake: false,
theme: 'material'
});
}])
.config(function($stateProvider, $urlRouterProvider, $locationProvider, helloProvider, toastrConfig) {
helloProvider.init({
facebook: '1234567899',
google: '12345890-wgewrgwrgwrgrgwr.apps.googleusercontent.com',
twitter: 'wgwerwrgwrgwrgwrgwrw'
}, {
redirect_uri: 'redirect.html',
oauth_proxy: 'https://auth-server.herokuapp.com/proxy',
oauth_version: '1.0a' // probably 1.0a with hello.js
});
定義「優化」。您是否測量過這些功能太慢而無法執行,並導致性能問題?如果沒有,爲什麼你認爲你應該優化它們? –
不,沒有性能問題。保持多個配置功能是一個好習慣嗎? – Anish