我正在使用Angular-Formly來創建一個表單,在其中輸入一個地址,並返回來自本地的地圖。我創建了一個自定義模板使用下列內容:如何使用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
。