1

我正在尝试使用 ngMap 指令之一创建自定义指令。形状,具体来说。

angular
  .module('seeMeApp', ['ngMap'])
  .directive('userPath', function () {
    return {
      restrict: 'E',
      scope: {
        user: '=userObj',
        weight: '=',
        opacity: '='
      },
      replace: true,
      template: '<shape name="polyline" path="{{user.pathCoordinates}}" geodesic="true" stroke-color="{{user.color}}" stroke-opacity="{{opacity}}" stroke-weight="{{weight}}"></shape>'
    };
  })

当我直接在 ngMap 的 map 指令中使用 shape 指令时,模型的变化会被插值并反映在 map 上。

<map ng-show="pathCoordinates.length > 0" center="{{pathCoordinates[pathCoordinates.length - 1]}}" zoom="15">
    <shape ng-if="pathCoordinates.length > 0" name="polyline" path="{{pathCoordinates}}" geodesic="true"
    stroke-color="{{mapConfig.color}}" stroke-opacity="{{mapConfig.opacity}}" stroke-weight="{{mapConfig.stroke}}"> </shape>

</map>

但是当我使用 Shape 创建自定义指令时,dom 会发生变化,但在 Map 上没有创建可见的形状。

我在这里创建了一个 plunker:

http://plnkr.co/qrRxYxORvdKdLANg50Yn

我错过了什么。谢谢

4

1 回答 1

0

replace: true

我认为这是与replace: true例如)相关的错误之一

要解决它,从您的指令声明中删除它应该可以工作replace: true

例如:

  .directive('userPath', function () {
    return {
      restrict: 'E',
      scope: {
        user: '=userObj',
        weight: '=',
        opacity: '='
      },
      template: '<shape name="polyline" path="{{user.pathCoordinates}}" geodesic="true" stroke-color="{{user.color}}" stroke-opacity="{{opacity}}" stroke-weight="{{weight}}"></shape>'
    };
  })

演示 - http://plnkr.co/edit/5OcOQWCp81HdIlsqXtPD?p=preview

在此处输入图像描述

于 2015-07-04T09:06:11.840 回答