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 に答える