我想知道如何将搜索按钮连接到输入字段。用AngularjS ng-click api搜索
controllers.js
angular.module('weatherApp.controllers', [])
.controller('weatherCtrl', function($scope, $http) {
$http.jsonp('http://api.openweathermap.org/data/2.5/find?q=' + $scope.SearchCity + '&type=like&APPID=&callback=JSON_CALLBACK')
.success(function(data){
console.log('success');
$scope.cities = data;
});
});
all.html
<input type="text" ng-model="SearchCity" placeholder="Search for city" />
<input type="submit" ng-click="Search" Value="Search" />
<tr ng-repeat="city in cities.list | limitTo: 10 | filter:SearchCity">
<td>{{city.name}}</td>
</tr>
app.js
angular.module('weatherApp', ['weatherApp.controllers', 'ngRoute']).config(['$routeProvider', function($routeProvider){
$routeProvider.when('/all', {templateUrl: 'templates/all.html', controller:'weatherCtrl'});
$routeProvider.otherwise({redirectTo: '/all'});
}]);
我在mozilla console中得到了这个:success Object {data:Object,status:200,headers:headersGetter/<(),config:Object,statusText:“load”}。它没有列出即将搜索的城市 –
尝试将此行更改为:console.log('success',data.data); – manzapanza