【发布时间】:2017-05-14 08:53:39
【问题描述】:
我的 app.js 文件中有以下配置函数和运行函数。优化这些功能方法的最佳方法是什么?我们可以将这些移到一个配置函数中吗? 或者我们可以将这些移动到另一个文件中并使用,如果是,请在评论中更新我的代码。
.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
});
【问题讨论】:
-
定义“优化”。您是否测量过这些功能执行速度太慢并导致性能问题?如果不是,您为什么认为应该优化它们?
-
不,没有性能问题。保留多个配置函数是一个好习惯吗?
标签: angularjs angularjs-directive angular-ui-router angularjs-scope