1

我收到此错误Error: Argument 'readingController' is not a function, got undefined.,页面上没有任何内容。我做错了什么?

var app = angular.module('Tutorials', ['functions', 'ui.utils', 'tutorials']).controller('main', function($scope, $element, Position, Romanize) {
$scope.sectionNumber = Position.sectionNumber;
$scope.tutorialNumber = Position.tutorialNumber;
$scope.questionNumber = Position.questionNumber;
$scope.sections = sections;
$scope.currentMaterials = []
    $scope.currentMaterial = "";

var readingController = function($scope, Romanize) {
    $scope.currentMaterials = $scope.sections[$scope.sectionNumber].tutorials[$scope.tutorialNumber].material;
    $scope.currentMaterial = $scope.currentMaterials[$scope.questionNumber];
    $scope.getRomanization = function(Romanize) {
        Romanize.get($scope.currentMaterial).then(function(d) {
            $scope.romanized = d;
        });

        $scope.$apply();
    };
    $scope.getRomanization(Romanize);
    $scope.$apply();

    $scope.checkRomanization = function(userRomanization) {
        if ($scope.romanized === userRomanization) {
            $scope.questionNumber++;
            $scope.getRomanization(Romanize);
        };
    }
};

$scope.loadFromMenu(0, 0, true);

}).config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider.when('/grammar/Reading/Basic Vowels', {
    templateUrl: '/grammar/Templates/Reading.html',
    controller: 'readingController'
}).when('/test/secondTab', {
    templateUrl: '/js/test/angular/views/secondTab.html',
    controller: 'SecondTabCtrl'
}).otherwise({
    redirectTo: '/'
});

$locationProvider.html5Mode(true);
}]);
4

2 回答 2

1

这是组织控制器(或应用程序的任何其他内容)的另一个示例:

angular.module('MyApp', [])

.config(['$routeProvider', function ($routeProvider) {
  $routeProvider
    .when('/', { controller: 'MainCtrl' })
    .when('/first-page', { controller: 'FirstCtrl' })
    .when('/second-page', { controller: 'SecondCtrl' });
}])

.controller('MainCtrl', ['$rootScope', '$scope', function ($rootScope, $scope) {
  // ...
}])

.controller('FirstCtrl', ['$scope', function ($scope) {
  // ...
}])

.controller('SecondCtrl', ['$scope', '$http', function ($scope, $http) {
  // ...
}]);

或者可能在自己的文件中,例如。foob​​ar.js

angular.module('MyApp').controller('FoobarCtrl', ['$scope', function ($scope) {
  // ...
}]);
于 2013-05-22T19:10:49.160 回答
0

Angular 查找在 Angular 模块中定义的控制器。

您已经定义了控制器功能,但您需要告诉 Angular:

app.controller('readingController', readingController)

或者,就像您对问题的评论之一所暗示的那样,只需在调用中定义控制器函数controller

app.controller('readingController', function($scope, Romanize) {
  // controller stuff
});
于 2013-05-22T16:50:26.093 回答