1

我想将传单插件与 Angular JS 一起使用。我在官方角度教程之后找到了这个指令 https://github.com/tombatossals/angular-leaflet-directive 我用 ngview 和 $routeProvider http://jsfiddle.net/dmpDu/6/创建了这个代码 地图显示但控制器中的参数未应用我在 chrome 的调试控制台中有此警告:“[AngularJS - Leaflet] 'center' 在当前范围内未定义,您是否忘记初始化它?”

如果我不使用 $routeProvider 并像这样声明我的控制器就可以了

app.controller("DemoController", [ "$scope", function($scope) {
           angular.extend($scope, {
               london: {
                   lat: 51.505,
                   lng: -0.09,
                   zoom: 4
               }
           });
       }]); 

如果我想像这样使用 routeprovider

app.config(function($routeProvider,  $locationProvider) {
    $routeProvider.
    when('/Home', {templateUrl: '/partials/HomeList.html', controller:  HomeListCtrl}).
    otherwise({redirectTo: '/Home'});
    $locationProvider.html5Mode(true);
});

并像这样定义控制器

function HomeListCtrl($rootScope,$scope,$routeParams, $location,$http) {
    activity_name = "home";
    console.log("test");

angular.extend($scope, {
               london: {
                   lat: 51.505,
                   lng: -0.09,
                   zoom: 4
               }
           });
}

中心未定义:p,我有错误

[AngularJS - Leaflet] 'center' is undefined in the current scope, did you forget to initialize it? 

你能给我一些帮助吗?谢谢

4

1 回答 1

2

在您的传单声明中,您有: center="center"

<leaflet defaults="defaults" center="center"  id="leaflet"></leaflet>

这是该指令缺失的中心。将其更改为中心 =“伦敦

<leaflet defaults="defaults" center="london"  id="leaflet"></leaflet>
于 2013-12-02T21:01:28.693 回答