Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在angular js中从控制器更改视图?_Javascript_Angularjs_Ngroute_Ng View_Angularjs Ng Route - Fatal编程技术网

Javascript 如何在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"

我是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") {
    $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");