我有一個非常簡單的設置在這裏Angular.JS約束力不工作
的index.html
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
</head>
<body ng-app="locationApp" ng-controller="locationController">
<button ng-click="getLocation()">Get Location</button>
<br />
Latitude: {{city.Latitude}} <br />
Longitude {{city.Longitude}} <br />
<script src="Scripts/lib/angular.min.js"></script>
<script src="Scripts/app.js"></script>
</body>
</html>
app.js:
var locationApp = angular.module('locationApp', []);
var locationController = locationApp.controller("locationController", function ($scope, $http) {
$scope.getLocation = function() {
$http.get("https://localhost:44320/api/location?cityName=sg").then(function (location) {
$scope.city = location;
});
}
});
當我點擊獲取地點按鈕,我的綁定{{city.Latitude}}和{{city.Longitude}}保持空白。
我試着在Chrome中設置一箇中斷點來調試,並且我的值顯示出來。所以我不確定我錯過了什麼。任何幫助?
我越來越開始新摘要響應後使用AngularJS 1.6
嘗試'緯度:{{locationController.city.Latitude}}
' –
它'location.data'你的情況。獲取請求正在返回整個請求對象,並且您需要'.data'。 – theleebriggs