在指令中使用 openlayers-directive

Use openlayers-directive inside a directive

我正在尝试在指令中使用 openlayers-directive:

var app = angular.module("demoapp", ["openlayers-directive"]);
app.directive('myDir', function () {
return {
      restrict: "E",
      replace: true,
      template: "<openlayers ol-center='center' height='480px' width='640px'></openlayers>"
  }
})

在html中:

<my-dir></my-dir>

但是当我这样做的时候,我有一个多目录错误

VM2731 angular.js:12221 Error: [$compile:multidir] Multiple directives [myDir, openlayers] asking for template on: <openlayers ol-center="center" height="480px" width="640px">

任何解释都会有用

谢谢!

这是fiddle

您的指令模板应该有自己的根 <div>,其中将放置 open-layers 指令。这样您就定义了一个单独的模板,可以在其中编译嵌套指令。

template: "<div><openlayers ol-center='center' height='480px' width='640px'></openlayers></div>"