如何在 electron-angular-boilerplate 中使用 $routeProvider 的解析?

How to use $routeProvider's resolve in electron-angular-boilerplate?

我在进入主控制器之前加载 JSON 数据时遇到问题。

我正在使用 this 项目作为我项目的模板。我基本上只改了dist/app/home/home.js 还有改的内容:

angular.module('WellJournal', ['uiGmapgoogle-maps', 'ngRoute'])
    .config(function (uiGmapGoogleMapApiProvider, $routeProvider) {
        uiGmapGoogleMapApiProvider.configure({
            libraries: 'geometry,visualization,places'
        });

        $routeProvider.when('/', {
            templateUrl: 'index.html',
            controller: 'MainController',
            resolve:  {
                markers: ['$http', function ($http) {
                    return $http.get('http://address/api/markers/').then(function (result) {
                        console.log(result.data);
                        return result.data;
                    });
                }]
            }
        });

        $routeProvider.otherwise({ redirectTo: '/' });
    })
    .controller('MainController', function ($scope, $uibModal) {
    //trying to access $scope.markers here
    }

问题是 markers: ['$http', function ($http) {...}] 不会被触发。于是查了一下默认加载页面的地址(window.location.href),原来是file:///home/myuser/path/to/project/dir/views/index.html(可以看到对应的代码here

所以它并没有真正设置服务器,只是打开本地文件(我猜?)。

如何触发此 $routeProvider.when(...) 子句?我完全可以做到吗?

谢谢。

如果其他人遇到同样的问题 - 我最终使用下一个方法:

angular.module('WellJournal', ['uiGmapgoogle-maps'])
        .run(function($http, $rootScope){
            $http.get('http://address/api/markers/').
            success(function(data, status, headers, config) {
                $rootScope.markers = data;
                $rootScope.$broadcast('markers-loaded');
            }).
            error(function(data, status, headers, config) {
                // log error
                alert('error');
            });
        })
        .factory('markers', function ($rootScope) {
            var markers;
            $rootScope.$on('markers-loaded', function(){
                markers = $rootScope.markers;
            });
            return {
                data: markers
            }
        })
        .config(function (uiGmapGoogleMapApiProvider) {
            uiGmapGoogleMapApiProvider.configure({
                libraries: 'weather,geometry,visualization,places'
            });
        })
        .controller('MainController', function ($scope, $uibModal, $http, $rootScope, markers) {
        // use data through markers argument
        //Warning! This doesn't assure that the data is loaded before page
        //I'm experiencing small visual lag while loading but this is the best I could do 
        }