I'm using AngularJS and jQuery for a project. When i typing input, ng-change is working.. But, when i using jquery input.val('blabla') ng-change is not working.. How can i report this change angularjs side? This is my code.. Apply or watch or other one?
// 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
};
}]);