$ http.get('example.com/api/json/'+'input.value')in angularjs控制器函數並更新{{data}}根據輸入實時輸入值來自angularjs,用於ulj http.get
var id="de1cfb221f978cebde0db9adfb5da6b9";
var city ="London";
angular.module('moo', [])
.controller('mooAngular', function($scope, $http) {
$http.get('http://api.openweathermap.org/data/2.5/weather?' +
'q=' +city +
\t '&appid=' + id
).
then(function(response) {
$scope.myData = response.data
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div class="container" ng-app="moo" ng-controller="mooAngular" ng-init="">
<p>T(K) ={{myData.main.temp}}°</p>
<input id="city" type="text" ng-change="city" name="city" placeholder="Enter name here" value="">
</div>
歡迎堆棧溢出。你應該讓你的文章更加精確。你的問題是什麼?你的代碼的結果是什麼?期望的結果是什麼? – gus27