我是新來的角js。我有搜索頁面輸入文本框來搜索customerId,但我想添加一個功能,我可以根據url字符串進行搜索。如何在AngularJS中追加查詢字符串到url?
例如,我的網址是:
http://localhost:8080/#/search
但我需要這樣的東西
http://localhost:8080/#/search?ACC34ff
http://localhost:8080/#/search?CustomerId,這樣我可以搜索基於客戶ID的URL也
有沒有人告訴我怎樣才能添加查詢字符串?
app.config(['$routeProvider',
function($routeProvider) {
$routeProvider
.when('/home', {
templateUrl: 'partials/home.html',
controller: 'homePageCtrl',
reloadOnSearch: true
}).when('/features', {
templateUrl: 'partials/features.html',
controller: 'featuresCtrl',
reloadOnSearch: false
}).when('/search', {
templateUrl: 'partials/search.html',
controller: 'searchCtrl',
reloadOnSearch: false
}).otherwise({
redirectTo: '/home'
});
}]);
控制器:
appControllers.controller('searchCtrl', ['$scope','$route','$filter', '$http', '$location','$window','$timeout',
function($scope, $route, $filter, $http, $location, $window, $timeout) {
$scope.searchCustomerFeatures = function() {
if($scope.customerId != null) {
$http.get('/getCustomerFeatures.do', {params: {'customerId': $scope.customerId}}).success(function (data) {
$scope.featuresJson = angular.toJson(data, true);
});
}
}
}]);
HTML:
<li ng-class="{active: isActive('/search')}" style="margin-left: 100px; text-decoration-color: black; font-size: 20px">
<a href="#search" role="tab" data-toggle="tab">Search</a>
</li >
搜索頁面:
感謝
我在控制器端不需要任何東西?我不清楚它將如何使用客戶ID – user3407267
當我使用http:// localhost:8080 /#/ search?ACC34ff而不是http:// localhost:8080 /#/搜索 – user3407267
我的不好。您需要設置控制器來讀取參數。 $ http.get('/ Search /'+ $ routeParams.customerId) .success(function(response){ .... }); – wduqu001