1
我有一個應用程序,從一個郵政編碼數據庫中檢索數據。它直到我嘗試獲取更多的數據後才能正常工作,然後我得到一個'object不是函數'的錯誤。數據交換採用JSON格式,並且在我已經選擇一個縣之後嘗試選擇一個縣,似乎工作得很好。AngularJS函數一次工作,然後與對象的錯誤不起作用
HTML /前端
<form ng-controller="SearchCtrl" id="search4Zips" name="search4Zips">
<div class="state" data-ng-init="searchState()">
<label for="stateSelection">State: </label>
<select name="stateSelection" ng-change="searchCounty()" ng-model="keywords.state">
<option ng-repeat="state in states" value="{{state.state}}">{{state.state}}</option>
</select>
</div>
<div class="county">
<label for="countySelection">County: </label>
<select name="countySelection" ng-change="areaData()" ng-model="keywords.county">
<option ng-repeat="county in counties" value="{{county.county}}">{{county.county}}</option>
</select>
</div>
<div class="results" style="margin-top: 10px;">
<button class="btn btn-primary">Add to Cart</button>
<table style="margin-top: 10px;">
<tr>
<th>Use Zip Code</th>
<th>Zip</th>
<th>City</th>
<th>Average Leads per Month</th>
</tr>
<tr ng-repeat="area in areaData" ng-model="keywords.area">
<td><input type="checkbox" name="zips[{{area.Zip}}]" value="add"></td>
<td>{{area.Zip}}</td>
<td>{{area.City}}</td>
<td>Needs Data</td>
</tr>
</table>
<button class="btn btn-primary">Add to Cart</button>
<pre style="font-size: 0.8em; line-height: 1em; margin-top: 10px;">{{result | json}}</pre>
</div>
</form>
控制器
angular.module( '應用',[ '部件'])
.controller('SearchCtrl', function($scope, $http, $locale) {
$scope.url = []; // The url of our search
$scope.matches = [];
$scope.areaData = [];
$scope.search = function() {
$scope.url = '/wp-content/themes/dt-the7-child/assets/search.php';
// Create the http post request the data, holds the keywords
// The request is a JSON request.
$http.post($scope.url, { "data" : $scope.keywords}).
success(function(data, status) {
$scope.status = status;
$scope.data = data;
$scope.matches = data;
$scope.result = data; // Show result from server in our debugging area
}).
error(function(data, status) {
$scope.data = data || "Request failed";
$scope.status = status;
});
};
$scope.searchState = function() {
$scope.url = '/wp-content/themes/dt-the7-child/assets/search_state.php';
// Create the http post request the data, holds the keywords
// The request is a JSON request.
$http.post($scope.url, { "data" : $scope.keywords}).
success(function(data, status) {
$scope.status = status;
$scope.data = data;
$scope.states = data;
$scope.result = data; // Show result from server in our debugging area
}).
error(function(data, status) {
$scope.data = data || "Request failed";
$scope.status = status;
});
console.debug($scope.keywords);
};
$scope.searchCounty = function() {
$scope.url = '/wp-content/themes/dt-the7-child/assets/search_county.php';
// Create the http post request the data, holds the keywords
// The request is a JSON request.
$http.post($scope.url, { "data" : $scope.keywords['state']}).
success(function(data, status) {
$scope.status = status;
$scope.data = data;
$scope.counties = data;
$scope.result = data; // Show result from server in our debugging area
}).
error(function(data, status) {
$scope.data = data || "Request failed";
$scope.status = status;
});
console.debug($scope.keywords);
};
$scope.areaData = function() {
$scope.url = '/wp-content/themes/dt-the7-child/assets/search_areaData.php';
// Create the http post request the data, holds the keywords
// The request is a JSON request.
$http.post($scope.url, { "data" : $scope.keywords['county']}).
success(function(data, status) {
$scope.status = status;
$scope.data = data;
$scope.areaData = data;
$scope.result = data; // Show result from server in our debugging area
}).
error(function(data, status) {
$scope.data = data || "Request failed";
$scope.status = status;
});
console.debug($scope.keywords);
};
});
神聖的廢話 - tastic-wonderfull-ness,你是完全正確的!非常感謝,我花了最後一點的時間,真的被卡住了!我設置了'$ scope.matches'而不是'$ scope.areaData',並將其作爲'ng-repeat =「在匹配區域''和blamo !!中迭代,它工作!再次感謝!不能接受2分鐘:D – DrCord
幾分鐘前剛剛得到相同的錯誤:)) – michael