将工厂添加到控制器时,简单的离子应用程序无法渲染

时间:2015-10-17 08:22:03

标签: angularjs ionic factory

我有一个用于从joshmorony.com映射的demo离子应用程序。当我将工厂引入控制器时,它会完全停止渲染。以下工作显示地图,但如果我将控制器行更改为标记为FAIL的控制器行,则它不会通过模拟器进行渲染。有什么想法吗?我在Visual Studio 2015中通​​过Ripple模拟器运行它。

// 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");
    });
});

1 个答案:

答案 0 :(得分:0)

看起来工厂必须退货。

我把它改为:

patient[0].height

})

基于http://viralpatel.net/blogs/angularjs-service-factory-tutorial/然后我可以取消注释FAIL线并且它可以工作。