Error: [ng:areq] Argument 'customersController' is not a function, got undefined
异常代码如下
<
body
ng-app
=
""
ng-controller
=
"customersController"
>
<
table
>
<
tr
ng-repeat
=
"x in names | orderBy : 'name'"
>
<
td
>
{{ x.name | uppercase }}
</
td
>
<
td
>
{{ x.country }}
</
td
>
</
tr
>
</
table
>
</
body
><
script
type
=
"text/javascript"
src
=
"
<%=
path
%>
/resource/js/angular.js"
></
script
>
<
script
type
=
"text/javascript"
>
function
customersController($scope) {
$scope.names = [ {
name :
'Jani'
,
country :
'Norway'
}, {
name :
'Hege'
,
country :
'Sweden'
}, {
name :
'Kai'
,
country :
'Denmark'
} ];
}
</
script
>
|
这个错误原因是版本不一致,从1.3.x之后的版本中不支持全局的function
修改为如下红色字体方式即可
<
body
ng-app
=
"app"
ng-controller
=
"customersController"
>
<
table
>
<
tr
ng-repeat
=
"x in names | orderBy : 'name'"
>
<
td
>
{{ x.name | uppercase }}
</
td
>
<
td
>
{{ x.country }}
</
td
>
</
tr
>
</
table
>
</
body
><
script
type
=
"text/javascript"
src
=
"
<%=
path
%>
/resource/js/angular.js"
></
script
>
<
script
type
=
"text/javascript"
>
angular.module( 'app',[]).controller( 'customersController' ,function ($scope) {
$scope.names = [ {
name :
'Jani'
,
country :
'Norway'
}, {
name :
'Hege'
,
country :
'Sweden'
}, {
name :
'Kai'
,
country :
'Denmark'
} ];
});
</
script
>
|