2016-03-01 199 views
1

url: http://api.abc.com/GetGPssearch = oxy & uid = 688-B65-462-F9-7A 假設我想搜索cor,那麼url會改變我點擊cor的搜索按鈕的那一刻。它應該像 http://api.abc.com/GetGPssearch = cor & uid = 688-B65-462-F9-7A。 json文件具有相同的字段,因此angular中的顯示函數的工作原理與url將會更改並且值也相同,但不是類型,名稱和編號。字段根據用戶搜索輸入更新URL。在搜索文本框中搜索氧氣時使用Angular

代碼是

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 = ''; 
}; 
    }); 

//這是搜索texbox代碼

<input type="text" ng-model="enteredValue" /> 
<button ng-click="reset()">Clear</button> 

//這是過濾器,我使用

<tr ng-repeat="x in dta | filter:enteredValue"> 

1)的用戶輸入氧基.click搜索。最初在http中的url得到http://api.abc.com/GetGPssearch = oxy & uid = 688-B65-462-F9-7A 。搜索結果以角度顯示

2)用戶輸入cor.click搜索。網址應該更新爲 http://api.abc.com/GetGPs搜索= COR & UID = 688-B65-462-F9-7A

3)顯示檢索結果中的角

回答

0

//.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 ....馬修回答上述問題及其正確