Javascript 如何在angular js中从控制器更改视图?
我是angular js新手,尝试使用Javascript 如何在angular js中从控制器更改视图?,javascript,angularjs,ngroute,ng-view,angularjs-ng-route,Javascript,Angularjs,Ngroute,Ng View,Angularjs Ng Route,我是angular js新手,尝试使用ng视图和ngRoute指令 我有一个loginPage.html,其中的登录按钮代码如下所示 <button class="button button-block" ng-click="login()">Log In</button> 如果response.status==true则我想将视图更改为/home。有人能告诉我怎么做吗 谢谢。使用$location.path: if(response.status == "true"
ng视图
和ngRoute
指令
我有一个loginPage.html,其中的登录按钮代码如下所示
<button class="button button-block" ng-click="login()">Log In</button>
如果response.status==true
则我想将视图更改为/home
。有人能告诉我怎么做吗
谢谢。使用
$location.path
:
if(response.status == "true") {
$location.path('/home');
}
此外,您还没有在控制器依赖性列表中添加$location
:
function($scope, $http, $location)
不要忘记向控制器参数添加$location
,如下所示:
['$scope', '$http', '$location', function($scope, $http, $location)...
另外,将else
语句用括号括起来,否则只有第一行在语句中:
else {
$scope.error="Invalid login! Please try again";
$scope.user.email="";
$scope.user.password="";
}
谢谢,成功了!我忘了将$location添加到控制器参数中
['$scope', '$http', '$location', function($scope, $http, $location)...
else {
$scope.error="Invalid login! Please try again";
$scope.user.email="";
$scope.user.password="";
}
if(response.status == "true")
$location.path("/home");