//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