2016-08-11 16 views
0

私はMobileFirst v8とIonic v1.3.1を使ってアプリケーションをビルドしています。アプリが起動し、私は私のapp.jsファイル非同期タスクが終了するのを待つAngular JSを開始する前に

で正規のイオン角度コードを持っている場合はこれがapp.js

.run(function($ionicPlatform) { 
    $ionicPlatform.ready(function() { 
    ... 
    }) 
.controller('IndexCtrl', function($scope, $state) { 
    RememberMeService.checkIfLoggedIn().success(function(data) { 
     alert("YAY!!"); 
    }).error(function(data) { 
     alert('fail :('); 
    }); 

}); 

function wlCommonInit() { 
var serverUrl = WL.App.getServerUrl(function(success){ 
    console.log(success); 
}, function(fail){ 
    console.log(fail); 
}); 

WLAuthorizationManager.obtainAccessToken().then(
    function (accessToken) { 
     console.log(">> Success - Connected to MobileFirst Server");  
    }, 
    function (error) { 
     console.log(">> Failed to connect to MobileFirst Server"); 
     console.log(error);   
    } 
); 

これはRememberMeService

現在RememberMeServiceが呼ばれている何が起こる
.service('RememberMeService', function($q) { 
return { 
    checkIfLoggedIn: function() { 
     var deferred = $q.defer(); 
     var promise = deferred.promise; 
     var securityCheckName = 'UserLogin'; 

     WLAuthorizationManager.obtainAccessToken(securityCheckName).then(
       function (accessToken) { 
        console.log('USER IS LOGGED IN!!!'); 
       }, 
       function (response) { 
        console.log("obtainAccessToken onFailure: " + JSON.stringify(response)); 
      } 
     ); 

     promise.success = function(fn) { 
      promise.then(fn); 
      return promise; 
     } 
     promise.error = function(fn) { 
      promise.then(null, fn); 
      return promise; 
     } 

     return promise; 

    } 
} 
}) 

ですこの行の失敗時は、WLAuthorizationManagerが定義されていないと言われているので、WLAuthorizationManager.obtainAccessToken(securityCheckName).thenが失敗します。 app.jswlCommonInit()関数がまだ完了していないため、定義されていません。これは非同期関数です。

wlCommonInit()関数が終了し、WLAuthorizationManagerが定義されるまで、コントローラまたはサービスの呼び出しを延期するにはどうすればよいですか?助けのための

おかげ

EDIT

はここに私の新しいfunction wlCommonInit() {

function wlCommonInit() { 
var serverUrl = WL.App.getServerUrl(function(success){ 
    console.log(success); 
}, function(fail){ 
    console.log(fail); 
}); 

WLAuthorizationManager.obtainAccessToken().then(
    function (accessToken) { 
     console.log(">> Success - Connected to MobileFirst Server"); 
     angular.bootstrap(document.getElementById('indexBody'), ['app']); 
    }, 
    function (error) { 
     console.log(">> Failed to connect to MobileFirst Server"); 
     console.log(error);   
    } 
); 

私のindex.htmlが

<body id="indexBody"> 
    <h1>test</h1> 
</body> 

であると私はエラー

を取得
kError in Success callbackId: WLAuthorizationManagerPlugin887134242 : Error: [$injector:modulerr] Failed to instantiate module ng due to: 
TypeError: Cannot set property 'aHrefSanitizationWhitelist' of null 

私はあなたがwlCommonInit成功コールバックに手動で角度のAppをブートストラップすることができ、正しく

+1

角度コンポーネントで 'WLAuthorizationManager'をラップし、グローバル変数として使用しないでください。あなたが本当にこれを行うことができない場合は、角度の手動ブートストラップ方法を使用して準備ができたら、あなたのアプリを起動します。 – mguimard

+0

@「WLAuthorizationManagerを角型コンポーネントでラップし、それをグローバル変数として使用しない」と言ったときに、サービスでラップすることを意味しますか? – iqueqiorio

+0

はい、新しいサービスや工場では、この新しいコンポーネントに対して 'wlCommonInit'メソッドを公開し、それを呼び出して終了を待つことができます。とにかく、これはグローバル変数を使用することをお勧めします(あなたがうまく行っていない限り)。編集:私は実際にMobileFirst V8については何も知らないし、接頭辞付きのメソッドもある:/ – mguimard

答えて

関連する問題