html - 从 Angular 中的输入控件更新 URL

标签 html angularjs http url input

当在搜索文本框 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/

相关文章:

html - 在不访问 HTML 源代码的情况下实现 Google Analytics

angularjs - 带有后端 api 的 webpack-dev-server

AngularJS 在 Application .run 方法上设置变量。稍后在 Controller 、服务、html中使用

html - 使用与文本不同的背景颜色绘制 HTML5 Canvas?

html - 图像 Bootstrap 导航栏旁边的居中文本

http - 数据包如何通过代理服务器到达目的地?

node.js - 确定 socket.io 是 TCP 还是 HTTP

php - 如何从 Web 委派长时间的后台任务,并在完成后恢复控制

javascript - 按字母顺序对列表中的文本范围进行排序

javascript - AngularJS 未捕获错误 : [$injector:modulerr] -- noob here