在ng map中,这有效:
<marker ng-repeat="helper in helpers" position="{{helper.position}}" optimized="false" icon={{helper.facebook.freshURL}}"></marker>
但如果我在“icon”中加入params:
<marker ng-repeat="helper in helpers" position="{{helper.position}}" optimized="false" icon="{url: '{{helper.facebook.freshURL}}', anchor: [0,0]}"></marker>
似乎url在url之前有一个带有“localhost:8000”的前缀,我收到一个错误:
GET http://localhost:8100/%7Burl:%20https://graph.facebook.com/1716361775351742/picture?type=normal,%20anchor:%20[0,0]} 404 (Not Found)
这是我的错误或语法错误吗?感谢。
答案 0 :(得分:2)
此行为与解析表达式时发生的JSON错误有关:{url: '{{helper.facebook.freshURL}}', anchor: [0,0]}
为icon
属性提供有效表达式后,例如icon='{"url":"{{helper.facebook.freshURL}}","anchor":[0,0]}'
,标记图标将正确初始化。
实施例
var app = angular.module('appMaps', ['ngMap']);
app.controller('mapCtrl', function ($scope) {
$scope.cities = [
{ id: 1, name : "Brisbane", location: [-33.867396, 151.206854] }
];
$scope.iconProperties = {
url : "http://maps.google.com/mapfiles/marker.png",
anchor: [0,0]
};
$scope.iconUrl = "http://maps.google.com/mapfiles/marker.png";
});
<script src="https://maps.googleapis.com/maps/api/js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script src="https://rawgit.com/allenhwkim/angularjs-google-maps/master/build/scripts/ng-map.js"></script>
<div ng-app="appMaps" ng-controller="mapCtrl">
<map center="[-24.667856, 133.630694]" zoom="3">
<!--marker id='ID{{city.id}}' ng-repeat="city in cities" position="{{city.location}}" icon="{{iconProperties}}" -->
<marker id='ID{{city.id}}' ng-repeat="city in cities" position="{{city.location}}" icon='{"url":"{{iconUrl}}","anchor":[0,0]}'>
</marker>
</map>
</div>
答案 1 :(得分:0)
是的,可能是个错误。到目前为止试图找到文档,但不能。可能是RegEx问题
如果还在查找,请删除协议然后尝试。所以你的网址看起来像这样。
helper.facebook.freshURL = '//graph.facebook.com/1716361775351742/picture?type=normal';
告诉我们。