2017-01-23 2 views
0

私のアプリでAuth0を使用して、ユーザーが認証されているかどうかを(テンプレート内で)チェックしています。以下のような何か:angularJSは条件付きでユーザーをリダイレクトします

!isAuthenticatedセクションで
<div ng-if="isAuthenticated" id="grid1" ui-grid="gridOptions" ui-grid-importer class="grid" ui-grid-resize-columns ui-grid-move-columns ui-grid-auto-resize ui-grid-selection ui-grid-cellNav ui-grid-paging myscroller></div> 
<div ng-if="!isAuthenticated"> 
    <p>You will be redirected because you are not authenticated</p> 
</div> 

、私はHTMLの中からユーザーをリダイレクトすることができますか?方法はありますか?

私は前にこのようなものを見ました:<meta http-equiv="refresh" content="2; URL=http://www.redirectedsite.com">しかし、これはメタタグとして適用されるようです。

答えて

1

あなたはコントローラーにngInit

<div ng-if="isAuthenticated" id="grid1" ui-grid="gridOptions" ui-grid-importer class="grid" ui-grid-resize-columns ui-grid-move-columns ui-grid-auto-resize ui-grid-selection ui-grid-cellNav ui-grid-paging myscroller></div> 
<div ng-if="!isAuthenticated"> 
    <p ng-init="redirect()">You will be redirected because you are not authenticated</p> 
</div> 

を使用することができます。

$scope.redirect = function() { 
    // redirecting in 1 sec... 
    $timeout(function() { 
     $location.path('/login'); 
    }, 1000); 
} 
関連する問題