0

我正在使用带角度的 requirejs,但无法让 Route 提供程序工作:

require.config({

// alias libraries paths
paths: {
    'angular': 'vendor/angular.min',
    'angularRoute': 'vendor/angular-route'
},

// angular does not support AMD out of the box, put it in a shim
shim: {
    'angular': {exports: 'angular'},
    'angularRoute':['angular']
},
priority: ["angular"]
});
require([
     'angular',
     'app'
     ],
    function(angular, app){
        'use strict';
        var $html = angular.element(document.getElementsByTagName('html')[0]);
        angular.element().ready(function() {
        $html.addClass('ng-app');
        angular.bootstrap($html, [app['name']]);
        app.config(['$routeProvider',
                    function($routeProvider){
                        $routeProvider.when('/',{
                            templateUrl: 'views/home.html',
                            controller:'MyCtrl1'
                        })
                        .when('/views2',{
                            templateUrl: 'views/home.html',
                            controller:'MyCtrl2'
                        })
                        .otherwise({
                            templateUrl: 'views/dontknow',
                            controller:'MyCtrl2'
                        })
                    }
        ]);
}); 
})

我的基本应用程序 URL 如下所示:http://example.com:8080/HOMEPAGE/ 当我输入http://example.com:8080/HOMEPAGE/#views2时不应该尝试拉 home.html 吗?

我的控制器如下所示:

define(['angular'], function (angular) {
'use strict';
var myController = angular.module('myController', []);
myController.controller('MyCtrl1', ['$scope', function ($scope) {
        $scope.greeting = "hello world";
    }]).controller('MyCtrl2', ['$scope', function ($scope) {
        $scope.greeting = "hello world2";
    }]);
return myController;

});
4

1 回答 1

2

我在我的应用程序中找到了问题的根源。我没有定义

<div ng-view>

</div>

显示我的控制器的结果

于 2013-10-29T22:27:29.527 回答