2016-10-15 7 views
0

私は、私のIonicプロジェクトでロールを使ってAuthを実行しようとしています。問題は、私が従っているプロジェクトが古いので、プロジェクトの構造に多少の違いがあることです。グローバル関数のapp.jsへ

http://plnkr.co/edit/Mvrte4?p=preview

このプロジェクトは、次のスクリプトがあります:

この

は、私は次のようだプロジェクトである

globalFunctions.js

/** 
* Contains functions that are added to the root AngularJs scope. 
*/ 
angular.module('loginApp').run(function($rootScope, $state, Auth, AUTH_EVENTS) { 

//before each state change, check if the user is logged in 
//and authorized to move onto the next state 
$rootScope.$on('$stateChangeStart', function (event, next) { 
    var authorizedRoles = next.data.authorizedRoles; 
    if (!Auth.isAuthorized(authorizedRoles)) { 
     event.preventDefault(); 
     if (Auth.isAuthenticated()) { 
     // user is not allowed 
     $rootScope.$broadcast(AUTH_EVENTS.notAuthorized); 
     } else { 
     // user is not logged in 
     $rootScope.$broadcast(AUTH_EVENTS.notAuthenticated); 
     } 
    } 
    }); 

/* To show current active state on menu */ 
$rootScope.getClass = function(path) { 
    if ($state.current.name == path) { 
     return "active"; 
    } else { 
     return ""; 
    } 
} 

$rootScope.logout = function(){ 
    Auth.logout(); 
}; 

}); 

そう ...私のプロジェクトでは、上記のスクリプトのようなファイルはありませんが、私は持っています: 私は私のスクリプトapp.jsでglobalFunctions.jsをマージするにはどうすればよい

angular.module('restaurant', [ 
'ionic', 
'ionic.service.core', 
'ionic.service.push', 

'ngCordova', 
'ionic-toast', 
'LocalStorageModule', 
'firebase', 

'config', 
'restaurant.restaurant-cart', 
'restaurant.restaurant-delivery', 
'restaurant.categories', 
'restaurant.products', 
'restaurant.news', 
'restaurant.map', 
'restaurant.home', 
'restaurant.cancha', 
'restaurant.ultimasoperaciones', 
'restaurant.push', 
'restaurant.menu', 
'restaurant.listanegra', 
'restaurant.login', 
'restaurant.agenda', 
'restaurant.contacto', 
'restaurant.infocancha', 
'restaurant.wordpress', 
'restaurant.drupal', 
'restaurant.favorites', 
'gMaps' 
]) 

.value('_', window._) 

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

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

.config(function($urlRouterProvider) { 
// if none of the above states are matched, use this as the fallback 
    $urlRouterProvider.otherwise('/app/login'); 
}); 

をapp.js? 別のスクリプトを作成する必要がありますか?私はプロジェクトの構造を維持したい。

ありがとうございました!

+1

を忘れて、その中にすべての' globalFunctions'機能を入れてはいけません。 –

+0

ああ。ありがとう!! –

+0

まあ私はあなたがこの2つの間で共通としてangular.moduleを取る必要があると思うと、あなたのビュー(index.htmlまたは何か他のもの)に両方のファイルを含める必要があります。それは簡単ですし、手動でこれをマージする必要はありません。 – Jigar7521

答えて

0

これらの機能をapp.jsにコピーできます。 3つのスペースがあり、必要に応じてグローブ機能を貼り付けることができます。それらの外の.config 3)内部.RUN 2)内部 1)は、両方の

は `utilities`角度サービスを作成し、依存関係に

関連する問題