//login.html
<div ng-controller="loginController">
<form action="/" id="myLogin">
User Name:<input type="text" ng-model="uname" /> <br />
Password: <input type="password" ng-model="passwd"/> <br />
<button type="button" ng-click="submit()">login</button>
</form>
</div>
//controller.js
var app = angular.module('myApp', ['ngRoute']);
app.config(function($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'login.html'
})
.when('/employeeReg', {
templateUrl: 'employeeReg.html'
})
.otherwise({
redirectTo:'/'
})
});
app.controller('loginController', function($scope, $location) {
$scope.submit = function() {
if ($scope.uname == 'admin' && $scope.passwd == 'admin') {
$location.path('employeeReg.html');
} else {
alert('login failed');
}
};
});
我很新的角度JS,此示例代碼是隻需登錄頁面,但是當我打開索引頁沒有什麼是可見的,它應該重定向到登錄page.any幫助將受到歡迎。
哪裏是你的索引頁的代碼? – NNR
感謝您的回覆,實際上我已經添加了代碼的屏幕截圖,但它不顯示在這裏..https://i.stack.imgur.com/GBdze.png在此鏈接索引代碼可用。 – krish
Where is the路由索引頁面在你的控制器內 – NNR