我正在为项目使用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
};
}]);
答案 0 :(得分:1)
只需使用:
$('.city-input').val('İstanbul');
而不是:
SELECT /* ROUTEID */
ROUTES.[RouteId] AS ROUTEID,
/* ROUTE STARTDATETIME */
ROUTES.[DateTime] AS ROUTESTARTDATETIME,
/* ROUTE DESCRIPTION */
{Route}.[Description],
/* NAME OF THE DRIVER */
{Driver}.[Name],
/* VEHICLE LICENSE PLATE */
{Vehicle}.[Registration],
/* QUANTITY OF STOPS */
(SELECT COUNT({RouteStop}.[RouteId])
FROM {RouteStop}
WHERE {RouteStop}.[RouteId] = ROUTEID) AS STOPCOUNT,
/* AMOUNT OF FUEL */
(SELECT SUM(FUEL.[Value])
FROM {GPS} FUEL
WHERE ROUTES.[AvailabilityId] = FUEL.[AvailabilityId]
AND TRUNC(ROUTES.[DateTime]) = TRUNC(FUEL.[DateTime])
AND FUEL.[EventTypeId] = @FuelEventTypeId) AS FUELAMOUNT,
/* ROUTE ENDDATETIME */
(SELECT ROUTEENDDATETIME.[DateTime]
FROM {GPS} ROUTEENDDATETIME
WHERE ROUTEID = ROUTEENDDATETIME.[RouteId]
AND ROUTEENDDATETIME.[EventTypeId] = @RouteCompletedEventTypeId
AND ROWNUM = 1) AS ROUTEEND,
/* INITIAL MILEAGE */
(SELECT INITIALMILEAGE
FROM (SELECT MILEAGEBEGIN.[Value] AS INITIALMILEAGE
FROM {GPS} MILEAGEBEGIN
WHERE ROUTES.[AvailabilityId] = MILEAGEBEGIN.[AvailabilityId]
AND TRUNC(ROUTES.[DateTime]) = TRUNC(MILEAGEBEGIN.[DateTime])
AND MILEAGEBEGIN.[EventTypeId] = @MileageEventTypeId
ORDER BY MILEAGEBEGIN.[DateTime] ASC
)
WHERE ROWNUM = 1),
/* FINAL MILEAGE */
(SELECT FINALMILEAGE
FROM (SELECT MILEAGEEND.[Value] AS FINALMILEAGE
FROM {GPS} MILEAGEEND
WHERE ROUTES.[AvailabilityId] = MILEAGEEND.[AvailabilityId]
AND TRUNC(ROUTES.[DateTime]) = TRUNC(MILEAGEEND.[DateTime])
AND MILEAGEEND.[EventTypeId] = @MileageEventTypeId
ORDER BY MILEAGEEND.[DateTime] DESC
)
WHERE ROWNUM = 1)
FROM {GPS} ROUTES
INNER JOIN {Route}
ON ROUTES.[RouteId] = {Route}.[Id]
INNER JOIN {Availability}
ON ROUTES.[AvailabilityID] = {Availability}.[Id]
INNER JOIN {Driver}
ON {Availability}.[DriverId] = {Driver}.[Id]
INNER JOIN {Vehicle}
ON {Availability}.[VehicleId] = {Vehicle}.[Id]
WHERE ROUTES.[EventTypeId] = @RouteStartedEventTypeId