【发布时间】:2016-07-07 19:19:40
【问题描述】:
我正在使用 Angular-Formly 创建一个表单,您可以在其中输入地址并从该本地返回地图。我使用以下内容创建了一个自定义模板:
<script type="text/ng-template" id="leaflet-map-template.html">
<div id="[options.key]"></div>
</script>
并将类型设置为angular.module 与其他模块:
var app = angular.module('formlyExample', [
'ngAnimate',
'ngSanitize',
'ngTouch',
'formly',
'formlyBootstrap',
'ui.bootstrap'
], function config(formlyConfigProvider) {
// set custom template here
formlyConfigProvider.setType({
name: 'leaflet-map',
templateUrl: 'leaflet-map-template.html'
});
});
但在现场我不知道如何初始化传单地图。这是我的字段数组的一部分:
vm.formFields = [
//other fields come here
//leaflet map template
{
key: 'mymap',
type: 'leaflet-map',
templateOptions: {
label: 'Leaflet Map'
},
controller: /* @ngInject */ function($scope) {
var initialCoordinates = [-23.0895164, -47.2187371];
// initialize map with initial coordinates
var map = L.map($scope.options.key, {
center: initialCoordinates,
zoom: 14,
zoomControl: false
});
}
}];
--编辑--
它给我的错误是:Map container not found,因为它找不到div。
【问题讨论】:
标签: javascript angularjs leaflet angular-formly