2015-10-17 44 views
0

我有一个用于从joshmorony.com进行映射的演示程序。当我将工厂引入控制器时,它会完全停止渲染。下面的工作来显示地图,但如果我将控制器行更改为标记为FAIL的控制器行,则它不会通过仿真器进行渲染。任何想法为什么?我从Visual Studio 2015年向控制器添加工厂时不呈现简单离子应用程序

// Ionic Starter App 
 

 
// angular.module is a global place for creating, registering and retrieving Angular modules 
 
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html) 
 
// the 2nd parameter is an array of 'requires' 
 
angular.module('starter', ['ionic', 'ngCordova']) 
 

 
.run(function ($ionicPlatform) { 
 
    $ionicPlatform.ready(function() { 
 
     // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard 
 
     // for form inputs) 
 
     if (window.cordova && window.cordova.plugins.Keyboard) { 
 
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
 
     } 
 
     if (window.StatusBar) { 
 
      StatusBar.styleDefault(); 
 
     } 
 
    }) 
 
}) 
 

 
.config(function ($stateProvider, $urlRouterProvider) { 
 

 
    $stateProvider 
 
    .state('map', { 
 
     url: '/', 
 
     templateUrl: 'templates/map.html', 
 
     controller: 'MapCtrl' 
 
    }); 
 

 
    $urlRouterProvider.otherwise("/"); 
 

 
}) 
 

 

 
.factory('JMGoogleMaps', function($cordovaGeolocation) { 
 

 
    function initMap(){ 
 
     
 
    }; 
 

 
}) 
 

 
**// FAILS to render at all... 
 
// .controller('MapCtrl', function ($scope, $state, $cordovaGeolocation, JMGoogleMaps) {** 
 
.controller('MapCtrl', function ($scope, $state, $cordovaGeolocation) { 
 

 
    var options = { timeout: 10000, enableHighAccuracy: true }; 
 

 
    $cordovaGeolocation.getCurrentPosition(options).then(function (position) { 
 

 
     var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude); 
 

 
     var mapOptions = { 
 
      center: latLng, 
 
      zoom: 15, 
 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
 
     }; 
 

 
     $scope.map = new google.maps.Map(document.getElementById("map"), mapOptions); 
 

 
     //Wait until the map is loaded 
 
     google.maps.event.addListenerOnce($scope.map, 'idle', function() { 
 

 
      var marker = new google.maps.Marker({ 
 
       map: $scope.map, 
 
       animation: google.maps.Animation.DROP, 
 
       position: latLng 
 
      }); 
 

 
      var infoWindow = new google.maps.InfoWindow({ 
 
       content: "Here I am!" 
 
      }); 
 

 
      google.maps.event.addListener(marker, 'click', function() { 
 
       infoWindow.open($scope.map, marker); 
 
      }); 
 

 
     }); 
 

 
    }, function (error) { 
 
     console.log("Could not get location"); 
 
    }); 
 
});

回答

0

它看起来像工厂已返回的东西中运行它通纹波模拟器。

我把它改为:基于http://viralpatel.net/blogs/angularjs-service-factory-tutorial/

.factory('JMGoogleMaps', function ($cordovaGeolocation) { 

var fac = {}; 

fac.users = ['John', 'James', 'Jake']; 

return fac; 

})

,然后我可以取消对失效线和它的作品。