我有一個自定義控件的谷歌地圖,我希望它點擊時打開離子模式。我有另一個控制從地圖清除標記,它工作正常。從Google地圖自定義控件打開離子模式的問題
如果我把modal.show
作爲按鈕的函數,當我點擊它的時候,我得到了「無法讀取屬性」$ $$'undefined'。
如果我把modal.show()
模式打開時頁面加載,我不想要的,然後將不會再次打開時,我點擊按鈕。
控制器
.controller('MapCtrl', function(mapServ, mapFact, $ionicModal, $scope){
var vm = this;
var gmap = mapServ.init();
var markers = mapServ;
// Create modal and Custom Map Controls
$ionicModal.fromTemplateUrl('templates/modal.html', {
scope: $scope
}).then(function(modal) {
vm.modal = modal;
var controlContainer = document.createElement('div');
var clearControl = new mapFact.Control(controlContainer, 'Clear Map', mapFact.clearMap);
var locControl = new mapFact.Control(controlContainer, 'Locations', vm.modal.show());
controlContainer.index = 1;
gmap.controls[google.maps.ControlPosition.TOP_RIGHT].push(controlContainer);
});
// Create Markers
mapFact.markers($rootScope.rests, gmap).then(function(results) {
mapServ.markers = results;
vm.markers = mapServ.markers;
});
});
從工廠
// Button Constructor
map.Control = function(controlDiv, text, func) {
// Set CSS for the control border.
var controlUI = document.createElement('div');
controlUI.style.backgroundColor = '#ed5929';
controlUI.style.border = '2px solid #ed5929';
controlUI.style.borderRadius = '3px';
controlUI.style.boxShadow = '0 2px 6px rgba(0,0,0,.3)';
controlUI.style.cursor = 'pointer';
controlUI.style.marginBottom = '22px';
controlUI.style.marginRight = '22px';
controlUI.style.marginTop = '22px';
controlUI.style.textAlign = 'center';
controlUI.title = 'Click to toggle markers';
controlDiv.appendChild(controlUI);
// Set CSS for the control interior.
var controlText = document.createElement('div');
controlText.style.color = 'rgb(255,255,255)';
controlText.style.fontWeight = 'bold';
controlText.style.fontFamily = 'Roboto,Arial,sans-serif';
controlText.style.fontSize = '16px';
controlText.style.lineHeight = '38px';
controlText.style.paddingLeft = '5px';
controlText.style.paddingRight = '5px';
controlText.innerHTML = text;
controlUI.appendChild(controlText);
controlUI.addEventListener('click', func);
};
請澄清,你想究竟達到什麼樣的輸出?首先,你說「我希望它在點擊時打開離子模式」,但你也說「如果我把modal.show()模式打開,當頁面加載,我不想要」。而且,你還可以在使用'modal.show()'的時候分享錯誤日誌嗎? :) – Teyam
對不起,如果我不清楚。我希望按鈕打開模式,但我不希望它在頁面加載時自動打開。當我使用'modal.show()'時,沒有任何錯誤只是在頁面加載時打開模式,然後在按下按鈕時沒有任何反應。 –