我正在用angular.js構建一個Ionic應用程序,我快完成了,但現在我遇到了一些小麻煩。無法更新angular.js中的變量
在我templates/menu.html
我:
<ion-item nav-clear menu-close ng-click="filterByPeriod(weekBegin, currentDate)">Filter </ion-item>
和我controller.js:
.controller('Home', ['$scope', '$ionicModal', '$cordovaGeolocation', function($scope, $ionicModal, $cordovaGeolocation) {
App = {
init: function() {
setTimeout(function(){
$scope.map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
}, 200);
},
};
$scope.addMarkersToMap = function(reports, map) {
var newCenter = new google.maps.LatLng(reports[0].latitude, reports[0].longitude);
map.setCenter(newCenter);
map.setZoom(12);
}
$scope.filterByPeriod = function(beginDate, endDate) {
var cityId = window.localStorage.getItem('cityId');
serviceReports.getDenunciasFromPeriod(cityId, beginDate, endDate)
.success(function(reports){
$scope.addMarkersToMap(reports.dados, $scope.map);
});
}
App.init();
}]);
我已經嘗試用`$ scope.apply做到這一點(函數(){})來封裝此方法,但用這兩種方式我趕上這個錯誤:
http://cl.ly/image/200O1d2F1C46
任何人都有任何想法如何解決這個問題?
的錯誤信息表明'map'內'$ scope.addMarkersToMap()'是未定義/空。仔細檢查你是否正在爲該函數調用提供一個實際對象。 – Clev3r 2014-10-01 03:24:54
你可以分享你如何設置你的mapOptions嗎? – benek 2014-10-01 13:17:15