2
嗨我有一個表格,我發送searched term
和category id
。它可以正常工作,因爲我正在發送這兩種東西,但是如果用戶沒有輸入任何東西,只有「類別ID」會去,而在後端如果searched term
爲空,所有結果都會顯示給用戶。如何在角Js中的routeparams發送空字符串?
但是,如果我在路由參數中發送空字符串,我將重定向到我的index
頁面。這是我的app.js
代碼。
when('/subcategory/:subcatId/:search', {
templateUrl: 'partials/subcategory.html',
controller: 'SubCategoriesController'
}).
我的形式
<form name="searchCategoryForm">
<div class="col-md-9 col-xs-10 col-sm-10">
<input class="form-control" placeholder="Find your item here...." ng-model="search" type="text" style="color:#09669c;">
</div>
<div class="col-md-2 col-xs-2 col-sm-2">
<a class="btn btn-primary" role="button" href='#/subcategory/{{cats[clicked_category].id}}/{{search}}'> Search</a>
</div>
</form>
我controller.js
$scope.search_term = $routeParams.search;
$scope.category_id = $routeParams.subcatId;
/* Search category form */
$scope.search_category = function() {
$http({
method: 'GET',
url: 'abc',
params: {"name": $scope.search_term, "category_id": $scope.category_id},
headers: {'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': $rootScope.keyword_auth_token}
})
.success(function (data) {
$scope.search_category_result = data.items;
console.log($scope.search_category_result);
})
.error(function (data) {
console.log(data);
});
};
/* Search category form ends here*/
if ($scope.search_term && $scope.category_id)
{
$scope.search_category();
}
Hats Off Sir :) –
但是....那麼我的頭就會變冷;) – Robba
你是怎麼知道的?它是否寫在文檔中? –