私は同じ問題に苦労してきました。この質問を投稿しました。答えはいくつかの光を当てます。その後、ユーザーにログインを強制することができました。そうして初めて、ユーザーはナビゲーションバーの他のリンクにアクセスできるようになります。次に、ログイン画面にナビゲーションバーが表示されるという問題がありました。だから私は回避策を作成しました:
1)ページを分割しました:使用すると、デフォルトng-include
でロードできました。ありません。login.html
login.html
index.html
ng-view
2) ユーザーが認証されたらng-view
、ナビゲーションで必要なすべてのビューが機能するように含める必要があります。
index.html
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<link rel="stylesheet" href="style.css" />
<script src="angular.min.js"></script>
<script src="angular-route.min.js"></script>
<script src="app.js"></script>
</head>
<body ng-controller="AppCtrl">
<div ng-include="template.url"></div>
</body>
</html>
login.html
<h1>Login Page</h1>
<form ng-submit="login(username, password)">
<label>User name</label>
<input type="text" ng-model="username" class="ng-pristine ng-valid">
<label>Password</label>
<input type="password" ng-model="password" class="ng-pristine ng-valid">
<br/>
{{loginError}} {{loggedUser}}
<br/><br/>
<button class="btn btn-success" ng-click="">Submit</button>
<button class="btn btn-warning" ng-click="cancel()">Cancel</button>
</form>
次に、認証が成功したら、テンプレート ( ng-include
) を変更しhome.html
、既定のページを作成します。
app.controller('AppCtrl', function($scope, authentication) {
$scope.templates =
[
{ url: 'login.html' },
{ url: 'home.html' }
];
$scope.template = $scope.templates[0];
$scope.login = function (username, password) {
if ( username === 'admin' && password === '1234') {
authentication.isAuthenticated = true;
$scope.template = $scope.templates[1];
$scope.user = username;
} else {
$scope.loginError = "Invalid username/password combination";
};
};
};
Home.html にはng-view
通常の機能があり、ユーザーは他のページにアクセスできます。
これは私がこれまでに持っているものです。ここに実例があります。お役に立てば幸いです。