angular從網路獲取資料賦值
阿新 • • 發佈:2019-01-06
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="text/javascript" src="angular-1.3.0.js"></script>
<script type="text/javascript">
var app=angular.module("myApp",[]);
app .value("url","https://free-api.heweather.com/v5/weather?city=beijing&key=545d63e185fc48169a43cbabba6e74d2");
app.controller("myCtrl",function ($scope,$http,url) {
$http.get(url).then(function (response) {
$scope.city = response.data.HeWeather5[0].basic.city;
$scope.now = response.data.HeWeather5[0].now.cond.txt;
},function (response) {
console.log(response.status);
});
})
</script>
</head>
<body ng-app="myApp">
<div ng-controller="myCtrl">
<div>城市:{{city}}</div>
<div> 天氣:{{now}}</div>
</div>
</body>
</html>