![](/img/trans.png)
[英]Is an undefined ng-bind more expensive than an ng-bind and ng-show?
[英]Why is this simple ng-bind and ng-show not working?
我正在嘗試顯示從Google地方信息服務獲取的數據。 出於某種原因,我可以將對象記錄到控制器內部的控制台中,但是在HTML文件中,偽指令根本不會被填充。由於我沒有使用映射,因此我為節點傳遞了div元素。 似乎沒有在線指南以這種方式顯示屬性,因此我嘗試將對象分配給作用域變量並以這種方式顯示。 $scope.location
將完美可行的對象打印到控制台屏幕,但是ng-bind
或ng-show
指令無法產生任何結果。
controllers.js
Controllers.controller("LocationController", ["$routeParams", "$scope", "$location", function($routeParams, $scope, $location) {
if (!$routeParams.placeId) return $location.path("/");
var PlaceService;
$(document).ready(function() {
PlaceService = new google.maps.places.PlacesService(document.getElementById("locationContainer"));
});
PlaceService.getDetails({ placeId: $routeParams.placeId }, function(place, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
$scope.location = place;
return console.log($scope.location);
}
return console.log("ERROR: " + status);
});
}]);
location.html:
<div class="container-fluid">
<div class="row">
<div class="col-xs-12">
<div class="col-xs-4">
<img ng-src="{{ location.icon }}">
</div>
<div class="col-xs-8">
<p ng-bind="location.name"></p>
</div>
</div>
</div>
</div>
<div id="locationContainer"></div>
控制台輸出: Object { address_components=[9], adr_address="<span class="street-addr...ountry-name">USA</span>", formatted_address="935 W Wisconsin Ave, Milwaukee, WI 53233, USA", more...}
這是您的異步通話。 更換
if (status == google.maps.places.PlacesServiceStatus.OK) {
$scope.location = place;
return console.log($scope.location);
}
與
$scope.$apply(function(){
if (status == google.maps.places.PlacesServiceStatus.OK) {
$scope.location = place;
return console.log($scope.location);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.