【问题标题】:angular leaflet custom markers (using angular directives)角度传单自定义标记(使用角度指令)
【发布时间】:2014-12-16 12:25:26
【问题描述】:

我正在尝试使用角度指令创建“传单标记”。出于设计目的,我们将演示文稿和模型分开,以便不同的人可以处理应用程序的不同部分。我的问题更有可能是“范围”问题而不是“传单”问题。我正在尝试传递要在 angular 指令中使用的对象,同时在控制器中的“$scope”上添加标记。在我的应用程序中,该指令“”是地图中要显示的每个标记对象上的“消息”属性中的唯一标记。它有一个属性“estacao”,在葡萄牙语中与“station”相同。

所以,我的代码在这里:

        angular.forEach($scope.estacoes, function(estacao) {
            $scope.markers.push({
                lat: estacao.latitude, 
                lng: estacao.longitude, 
                message: "<popup estacao='estacoes[" + i + "]'></popup>"
            });
            i++;
        });

http://plnkr.co/edit/evaQpqGZUz39Y7MNqbo7?p=preview

问题接缝是在处理指令时我的“estacao”为空。

谁能帮我弄清楚发生了什么?

【问题讨论】:

    标签: angularjs angularjs-directive leaflet angular-leaflet-directive


    【解决方案1】:

    弹出消息的“自动”编译(来自传单指令)使用根范围。 因此,您需要将响应 estacoes 分配给根范围:

    promiseEstacoes.then(function(estacoes) {
       $rootScope.estacoes = estacoes.estacoes;
       ...
    }
    

    http://plnkr.co/edit/OkQcth2zNrEdO2rgwBv8?p=preview

    【讨论】:

    • 谢谢你,Rob...它起作用了...但我不认为我真的明白发生了什么?但我会稍微研究一下这些不同的范围。再次感谢您花时间帮助我。
    • 看一下markersHelper代码中的manageOpenPopup()方法,你会看到编译调用(带有$rootScope)...
    【解决方案2】:

    使用最新版本的 angular-leaflet-directive,您可以指定用于消息渲染的范围:

    $scope.markers.push({
        lat: estacao.latitude, 
        lng: estacao.longitude,
        getMessageScope: function() { return $scope; }
        message: "<popup estacao='estacoes[" + i + "]'></popup>"
    });
    

    【讨论】:

    • 伟大的大卫...该解决方案也有效...感谢您花时间帮助我。
    猜你喜欢
    • 2017-03-30
    • 1970-01-01
    • 1970-01-01
    • 2017-04-24
    • 1970-01-01
    • 2020-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多