【发布时间】:2021-07-18 23:40:33
【问题描述】:
我正在尝试创建将来自外部源的地图嵌入 iframe 的指令,源是静态的,但参数将绑定到指令,并且可以由控制器控制,使 iframe 通过发送的新参数重新渲染实时。
代码:
angular.module('Utilities').directive('gisMap', [
'$sce',
function ($sce) {
return {
scope: {
location: '=',
},
restrict: 'EA',
transclude: true,
replace: true,
template: '<iframe src="{{ trustedUrl }}" frameborder="0" height="500" allowfullscreen="true" location="{{vm.location}}></iframe>',
link: function (scope, element, attrs) {
scope.trustedUrl = $sce.trustAsResourceUrl('https://myExternalGIS.com?find={{location}}');
},
controller: [
'$scope',
'$element',
function ($scope, $element) {
var self = this;
if ($scope.location=="") return;
},
],
controllerAs: 'vm',
bindToController: true,
};
},
]);
HTML:
<gis-map location="{{self.location}}"></gis-map>
我收到错误:
错误:[$compile:tplrt] 指令“gisMap”的模板必须有 正好是一个根元素。
【问题讨论】:
标签: angularjs angularjs-directive