I'm using angularjs and i'm using ng-if to show and remove a directive that is presenting a map from google maps, but every time i remove the directive and put it again the map doens't load and goes grey. Does anyone have any ideia or knows how i can solve this problem.
This is the accordion code:
<uib-accordion close-others="oneAtATime">
<uib-accordion-group ng-repeat="mission in missions" is-open="status.open">
<uib-accordion-heading >
<div class="noOutline">
<i class="fa fa-map-o fa-2x pull-left"></i>
{{mission.description}}
{{status.open}}
</div>
</uib-accordion-heading>
<missions-Map id='map' missionId='20' ng-if="status.open"></missions-Map>
</uib-accordion-group>
</uib-accordion>
This is the directive code:
angular.module("dronesIntershipProject").directive('missionsMap', function () {
var opened = false;
return {
restrict: 'E',
template: "<div></div>",
replace: true,
link: function(scope, element, attrs) {
console.log(attrs.ngIf);
var myLatLng = new google.maps.LatLng(20,20);
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
scrollwheel: true,
zoom: 8
});
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: "My Marker"
});
marker.setMap(map);
document.getElementById('map').removeAttribute("ng-if");
console.log(element);
}
}