我有一个非常简单的设置在这里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