AngularJS:当我使用jQuery的input.val()输入时,ng-change不起作用。
AngularJS:当我使用jQuery的input.val()输入时,ng-change不起作用。
我在一个项目中使用AngularJS和jQuery。当我输入时,ng-change工作正常。但是,当我使用jQuery的input.val(\'blabla\')时,ng-change不起作用。我应该如何在AngularJS中报告这个变化?这是我的代码。使用apply、watch还是其他方法?\n
// HTML // jQuery代码 $('.city-input').val('İstanbul'); // 所有的AngularJS代码 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 }; }]);