我在一个项目中使用 AngularJS 和 jQuery。当我输入输入时,ng-change 正在工作..但是,当我使用 jquery input.val('blabla') ng-change 时不起作用..我如何报告这个变化 angularjs 方面?这是我的代码.. 申请或观看或其他?
// Html
<input type="text" name="city" class="city-input req-string" rel="cityCtr" value="" ng-model="city" ng-change="findWeather(city)">
// jQuery code
$('.city-input').val('İstanbul');
// All AngularJS code
var app = angular.module('weatherApp', []);
app.controller('weatherCtrl', ['$scope', 'weatherService', function($scope, weatherService) {
function fetchWeather(city) {
weatherService.getWeather(city).then(function(data){
$scope.items = data;
});
}
$scope.findWeather = function(city) {
$scope.items = '';
fetchWeather(city);
alert(city);
};
}]);
app.factory('weatherService', ['$http', '$q', function ($http, $q){
function getWeather (city) {
var deferred = $q.defer();
var query = 'select * from weather.forecast where woeid in (select woeid from geo.places(1) where text="'+city+'")',
url = "http://query.yahooapis.com/v1/public/yql?q=" + query + "&format=json&callback=";
$http.get(url)
.success(function(data){
deferred.resolve(data.query.results.channel.item.forecast);
console.log(data)
})
.error(function(err){
console.log('Error retrieving markets');
deferred.reject(err);
});
return deferred.promise;
}
return {
getWeather: getWeather
};
}]);