我只是试图使角度引导工作在我希望仅在使用服务调用从服务器检索一些数据后才加载我的应用程序。但是我无法使用 $routeprovider 来完成这项工作。引导后我的路线不起作用。谁能知道我在这里做错了什么???
var myApp = angular.module('myApp', [ 'ngRoute', 'ui.bootstrap',
'dataHandler', 'underscore','ngAnimate', 'angular-loading-bar' ]);
fetchData();
function fetchData() {
var initInjector = angular.injector(["ng"]);
var $http = initInjector.get("$http");
return $http.get("/path/to/data.json").then(function(response) {
bootstrapApplication();
}, function(errorResponse) {
// Handle error case
bootstrapApplication();
});
}
function bootstrapApplication() {
angular.element(document).ready(function() {
myApp.config([ '$routeProvider', function($routeProvider) {
$routeProvider.when('/', {
redirectTo : '/dashboard'
}).when('/dashboard', {
menuItem: 'DASHBOARD',
templateUrl : '../views/customer/dashboard/customerDashboard.html',
controller : 'CustomerDashboardControllerPT',
controllerAs : 'custdashboard'
}).otherwise({
redirectTo : '/'
});
//$locationProvider.html5Mode(true);
}]);
angular.bootstrap(document, ["myApp"]);
});
}
它似乎也无法识别我的 MainController。在我的 html 文件中,我有如下代码:
<div class="container" ng-controller="MainController as main">
<div class="row">
<div class="col-sm-12"></div>
</div>
</div>
<script type="text/javascript"
src="../frameworks/jquery/jquery-1.11.2.min.js"></script>
<script type="text/javascript"
src="../frameworks/bootstrap/js/bootstrap.js"></script>
<script type="text/javascript" src="../frameworks/angular/angular.min.js"></script>
<script type="text/javascript"
src="../frameworks/angular/angular-route.js"></script>
<script type="text/javascript" src="../frameworks/angular/angular-animate.js"></script>
<script type="text/javascript" src="../frameworks/angular/ui-bootstrap.js"></script>
<script type="text/javascript" src="../frameworks/underscore/underscore.js"></script>
<script type="text/javascript" src="../frameworks/moment/moment.min.js"></script>
<script type="text/javascript" src="../frameworks/angular/loading-bar.js"></script>
<script type="text/javascript" src="../js/controllers/MainController.js"></script>