问题描述
我正在从AngularJS 1.2.26迁移到1.3.2,并收到错误
I'm migrating from AngularJS 1.2.26 to 1.3.2 and receive an Error
不是要解决的最佳错误消息,但似乎是在说我的控制器未定义?我可以不再以这种方式定义控制器吗?
Not the best error message to work out but it looks like it is saying that my controller is not defined? Can I no longer define controllers this way?
错误:error:areq
Error: error:areq
错误的论点
参数'welcomeController'不是aNaNunction,未定义
Argument 'welcomeController' is not aNaNunction, got undefined
我的索引页面类似于:
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular-route.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular-sanitize.min.js"></script>
var myApp = angular.module('kioskApp', ['ngRoute','ngSanitize']).run(function($rootScope, $location, $timeout) {
$rootScope.authenticated = true;
});
myApp.config(function($routeProvider, $locationProvider, $sceDelegateProvider) {
$routeProvider
.when('/welcome', {
templateUrl : 'pages/welcome.php',
controller : 'welcomeController'
});
});
function welcomeController($rootScope, $scope, $http, $location) {
//stuff
}
我的欢迎页面如下:
<div ontouchmove="preventDrag(event)" ng-show="authenticated">
<!-- some images -->
</div>
推荐答案
您可以使用controller: welcomeController
(不带引号)将其用作功能.否则,请执行myApp.controller('welcomeController', welcomeController)
之类的操作.
You could use controller: welcomeController
(without the quotes) to use it as a function. Otherwise, do something like myApp.controller('welcomeController', welcomeController)
.
您还应该学习依赖项注入语法
这篇关于参数不是aNaNunction,未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!