如何在 angularjs ajax 成功后更改 ui-view
How to change the ui-view after ajax success in angularjs
现在我正在尝试触发 ajax 进行搜索。在 $http( may be $resourse just ajax) 成功之后,我需要更新 index.page 中的 ui-view 以显示结果。这是我的代码:
angular.module('ecom').config(['$stateProvider','$urlRouterProvider',function($stateProvider,$urlRouterProvider){
//for any unmatched url,send to /dashboard
$urlRouterProvider.otherwise("/dashboard");
$stateProvider
.state('home',
{
url:'/home',
templateUrl:'submitter/home/home.html'
})
.state('expenses',
{
url:'/expenses',
templateUrl:'submitter/expenses/expense-list.html',
controller:'SubmitterExpensesCtrl'
})
.state('receipts',
{
url:'/receipts',
templateUrl:'submitter/receipts/receipts.html'
})
.state('settings',
{
url:'/settings',
templateUrl:'settings/settings.html',
controller:'SettingCtrl'
})
.state('logout',
{
url:'/logout',
templateUrl:'logout/logout.html',
controller:'LogoutCtrl'
})
.state('searchResult',
{
url:'/searchresult',
templateUrl:'ExpenseResult/searchresult.html',
controller:'resultCtrl'
})
}]);
This is index.page :
<nav><search></search></nav> // When click search, it will fire a ajax call, I will display the result in searchresult.html
<div class="body-container">
<div class="col-md-1"></div>
<div class="container app-wrapper col-md-12" ui-view></div> //the main content will display here.
<div class="col-md-1"></div>
</div>
<footer></footer>
如何将 url 更改为 /result 并在索引页中显示 searchresult.html?
我可以在 ajax seccuee 方法中尝试 $location.path('/searchresult') 吗?;
将 $state 注入您的控制器并在 $http/$resource 调用返回承诺后调用 $state.go(statename)。
所以在你的情况下,像...
$http.post("/ajax")
.then(function(data, status, headers, config) {
$state.go("searchResult");
})
现在我正在尝试触发 ajax 进行搜索。在 $http( may be $resourse just ajax) 成功之后,我需要更新 index.page 中的 ui-view 以显示结果。这是我的代码:
angular.module('ecom').config(['$stateProvider','$urlRouterProvider',function($stateProvider,$urlRouterProvider){
//for any unmatched url,send to /dashboard
$urlRouterProvider.otherwise("/dashboard");
$stateProvider
.state('home',
{
url:'/home',
templateUrl:'submitter/home/home.html'
})
.state('expenses',
{
url:'/expenses',
templateUrl:'submitter/expenses/expense-list.html',
controller:'SubmitterExpensesCtrl'
})
.state('receipts',
{
url:'/receipts',
templateUrl:'submitter/receipts/receipts.html'
})
.state('settings',
{
url:'/settings',
templateUrl:'settings/settings.html',
controller:'SettingCtrl'
})
.state('logout',
{
url:'/logout',
templateUrl:'logout/logout.html',
controller:'LogoutCtrl'
})
.state('searchResult',
{
url:'/searchresult',
templateUrl:'ExpenseResult/searchresult.html',
controller:'resultCtrl'
})
}]);
This is index.page :
<nav><search></search></nav> // When click search, it will fire a ajax call, I will display the result in searchresult.html
<div class="body-container">
<div class="col-md-1"></div>
<div class="container app-wrapper col-md-12" ui-view></div> //the main content will display here.
<div class="col-md-1"></div>
</div>
<footer></footer>
如何将 url 更改为 /result 并在索引页中显示 searchresult.html? 我可以在 ajax seccuee 方法中尝试 $location.path('/searchresult') 吗?;
将 $state 注入您的控制器并在 $http/$resource 调用返回承诺后调用 $state.go(statename)。
所以在你的情况下,像...
$http.post("/ajax")
.then(function(data, status, headers, config) {
$state.go("searchResult");
})