我是新来的角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