当在搜索文本框 url 中搜索 oxy 时: http://api.abc.com/GetGPs ?search=oxy&uid=688-B65-462-F9-7A 假设我想搜索 cor,那么当我点击 cor 的搜索按钮时,url 应该会改变。它应该像 http://api.abc.com/GetGPs ?search=cor&uid=688-B65-462-F9-7A。 json 文件具有相同的字段,因此 Angular 显示功能将与 url 一样工作,值也会改变,但类型、名称和编号不会改变。字段数
代码是
var countryApp = angular.module('countryApp', []);
countryApp.controller('CountryCtrl', function ($scope, $http){
$http.get('http://api.abc.com/GetGPs?**search=oxy**&uid=688-B65-462-F9-7A
').success(function(data) {
console.log(data);
$scope.dta = data.emp;
});
$scope.reset = function () {
$scope.enteredValue = '';
};
});
//这是搜索文本框代码
<input type="text" ng-model="enteredValue" />
<button ng-click="reset()">Clear</button>
//这是我正在使用的过滤器
<tr ng-repeat="x in dta | filter:enteredValue">
1) 用户输入 oxy .click 搜索。 url 最初在 http get http://api.abc.com/GetGPs ?search=oxy&uid=688-B65-462-F9-7A .搜索结果以 Angular 显示
2) 用户输入cor.click 搜索。 URL 应自行更新为 http://api.abc.com/GetGPs ?search=cor&uid=688-B65-462-F9-7A
3) 以 Angular 显示搜索结果
最佳答案
//.js
countryApp.controller('CountryCtrl', function($scope, $http) {
$scope.enteredValue = "*";
$scope.targetUrl = 'url';
$scope.reset = function() {
$scope.enteredValue = '';
};
$scope.doIt = function() {
$scope.targetUrl = 'http://api.abc.com/GetGPs?search=' + $scope.enteredValue + '&uid=688-B65-462-F9-7A';
$http.get( $scope.targetUrl )
.success(function(data) {
console.log(data);
$scope.dta = data.emp;
});
};
});
//html
<input type="text" ng-model="enteredValue" />
<button ng-click="doIt()">Submit</button>
<button ng-click="reset()">Clear</button>
https://plnkr.co/edit/6FJMnsA0rW54BLi6u5r7?p=preview plunker.... Matthew 对上述问题的回答及其正确
关于html - 从 Angular 中的输入控件更新 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35719277/