我收到此错误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);
}]);
答案 0 :(得分: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) {
// ...
}]);
或者也许在自己的文件中,例如。 foobar.js
angular.module('MyApp').controller('FoobarCtrl', ['$scope', function ($scope) {
// ...
}]);
答案 1 :(得分:0)
Angular查找在角度模块内定义的控制器。
你已经定义了控制器功能,但你需要告诉它角色:
app.controller('readingController', readingController)
或者,就像您的问题中的一条评论所暗示的那样,只需在controller
的调用中定义控制器功能:
app.controller('readingController', function($scope, Romanize) {
// controller stuff
});