我想制作$ http请求,获取结果并根据数据我将路由到view1或view2。我该怎么做角度?有人有例子吗?
应该是一些
$http({
url: 'API/v1/User/GetUserInfo',
method: "GET",
headers: { 'Content-Type': 'application/json' }
}).success(function (data, status, headers, config) {
//Something like this
var myVar=data.myVariable;
if(myVar==1){
$routeProvider.otherwise({ redirectTo: '/view1' });
}else{
$routeProvider.otherwise({ redirectTo: '/view2' });
}
}).error(function (data, status, headers, config) {
$scope.error = "There are problems with connection to server. Status:" + status + " Please, try to connect later.";
$scope.validationClass = "invalid";
});
之后
答案 0 :(得分:0)
使用$location
服务转到特定路径/路线。角度路由侦听位置上的更改,并将触发所有必要的操作。
if (myVar == 1) {
$location.url('/view1');
} else {
$location.url('/view2');
}