I am trying to create directive that will embed map from external source in an iframe, source is static but parameter will be bind to the directive and can be controlled by the controller makeing the iframe re-render by the new parameter sent in real time.
Code:
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>
I got error:
Error: [$compile:tplrt] Template for directive 'gisMap' must have exactly one root element.