【发布时间】:2015-02-10 20:43:19
【问题描述】:
所以我尝试为 Leaflet.js 创建指令,当我在指令中使用工厂时,一切正常
(function() {
'use strict';
angular
.module('directoryAppMap')
.directive('leafletDirective', function (Directory) {
return {
restrict: 'EA',
template:'<div></div>',
link: function (scope,element, attrs) {
var map = L.map(attrs.id, {
center: [40, -86],
zoom: 2
});
//create a CloudMade tile layer and add it to the map
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
maxZoom: 18
}).addTo(map);
Directory.get(function (data) {
L.geoJson(data).addTo(map);
});
}
};
});
})();
在我的控制器中,我做了一些事情并将其传递给查看
$scope.geojson = {};
$scope.FilteredGeojson = function () {
var result;
result = $filter('filter')($scope.data, $scope.search);
result = $filter('offset')(result, $scope.currentPage * $scope.pageSize);
result = $filter('limitTo')(result, $scope.pageSize);
$scope.geojson = result;
return result;
};
在表中一切正常我使用 ng-repeat 和 FilteredGeojson() 但是当我尝试将 $scope.geojson 传递给指令时,角度开始无限摘要循环并且地图没有任何 geojson
对上一个指令我使用添加
scope: {
data: '='
}
在我看来我通过了
data="geojson"
不幸的是,我不能将传单指令用于角度,因为有很多标记非常慢
【问题讨论】: