如何在angularJS中的同一个打开选项卡中重定向到页面

时间:2014-05-25 06:00:19

标签: javascript angularjs

如果登录成功,我想转到home.html页面。但是这个home.html页面会附加在同一个login.html页面中。我想只显示home.html而不是支持同一页面。这是我的代码 -

app.js -

angular.module('myApp', [
'ngRoute',
'myApp.filters',
'myApp.services',
'myApp.directives',
'myApp.controllers'
).
config(['$routeProvider', function($routeProvider) {
 $routeProvider.when('/home', {templateUrl: 'home.html', controller: 'MyCtrl1'});
 $routeProvider.otherwise({redirectTo: '/index'});
}]);

controller.js -

angular.module('myApp.controllers', [])
.controller('loginForm', function($scope,  $location) {
  $scope.users = [{name: "Neha", pwd: "Neha"}, {name: "Sneha", pwd: "Sneha"}];
  $scope.login = function (userName, password) {
    if (userName === "Neha" && password === "Neha") {
        alert("Welcome");
                    $location.path("/home");
    } else {
        alert("Invalid Login");
    }
  }
 });

login.html -

<body>
 <h1 class="title">EXPENSE SHARER MANAGER</h1>
  <div class="mainBdy" ng-controller="loginForm">
  <form ng-submit="login(userName, password)">
    <div class="userName">
      <label for="usrNm">USERNAME</label>
      <input type="text" id="usrNm" ng-model="userName"/>
    </div>
    <div class="password">
      <label for="pwd">Password</label>
      <input type="password" id="pwd" ng-model="password"/>
    </div>
    <div class="btnSection">
      <button>LOGIN</button>
      <button>SIGN UP</button>
    </div>
  </form>
</div>

home.html -

 <body>
  <h1 class="title">EXPENSE SHARER MANAGER</h1>
 </body>

请指导我哪里出错了。

0 个答案:

没有答案