仍然让 Controller 不是函数,未定义,而我没有全局定义控制器
still getting Controller not a function, got undefined, while I'm not defining controller globelly
仍然得到相同的错误 Argument 'AveragesCtrl' is not a function, got undefined
我已经尝试了 SO 上类似问题提供的所有解决方案,但没有运气,知道我做错了什么吗?
<div >
<div ng-controller="AveragesCtrl">
<table>
<tr ng-repeat="actor in avengers.cast">
<td>{{actor.name}}</td>
<td>{{actor.character}}</td>
</tr>
</table>
</div>
</div>
JS
var myApp = angular.module("myApp", []);
myApp.factory('Averages', function () {
var Avengers = {};
Avengers.cast = [
{
name: "Robert Downey Jr.",
character: "Tony Stark / Iron Man"
},
{
name: "Chris Evans",
character: "Steve Rogers / Captain America"
},
{
name: "Mark Ruffalo",
character: "Bruce Banner / The Hulk"
},
{
name: "Chris Hemsworth",
character: "Thor"
},
{
name: "Scarlett Johansson",
character: "Natasha Romanoff / Black Widow"
},
{
name: "Jeremy Renner",
character: "Clint Barton / Hawkeye"
},
{
name: "Tom Hiddleston",
character: "Loki"
},
{
name: "Clark Gregg",
character: "Agent Phil Coulson"
},
{
name: "Cobie Smulders",
character: "Agent Maria Hill"
},
{
name: "Stellan Skarsgard",
character: "Selvig"
},
{
name: "Samuel L. Jackson",
character: "Nick Fury"
},
{
name: "Gwyneth Paltrow",
character: "Pepper Potts"
},
{
name: "Paul Bettany",
character: "Jarvis (voice)"
},
{
name: "Alexis Denisof",
character: "The Other"
},
{
name: "Tina Benko",
character: "NASA Scientist"
}
];
return Avengers;
});
myApp.controller("AvengersCtrl", function AvengersCtrl(Avengers) {
var avengersCtrl = this;
avengersCtrl.avengers = Avengers;
});
没有控制器名称AveragesCtrl
您声明的控制器名称AvengersCtrl
转换这个
<div ng-controller="AveragesCtrl">
到
<div ng-controller="AvengersCtrl">
仍然得到相同的错误 Argument 'AveragesCtrl' is not a function, got undefined
我已经尝试了 SO 上类似问题提供的所有解决方案,但没有运气,知道我做错了什么吗?
<div >
<div ng-controller="AveragesCtrl">
<table>
<tr ng-repeat="actor in avengers.cast">
<td>{{actor.name}}</td>
<td>{{actor.character}}</td>
</tr>
</table>
</div>
</div>
JS
var myApp = angular.module("myApp", []);
myApp.factory('Averages', function () {
var Avengers = {};
Avengers.cast = [
{
name: "Robert Downey Jr.",
character: "Tony Stark / Iron Man"
},
{
name: "Chris Evans",
character: "Steve Rogers / Captain America"
},
{
name: "Mark Ruffalo",
character: "Bruce Banner / The Hulk"
},
{
name: "Chris Hemsworth",
character: "Thor"
},
{
name: "Scarlett Johansson",
character: "Natasha Romanoff / Black Widow"
},
{
name: "Jeremy Renner",
character: "Clint Barton / Hawkeye"
},
{
name: "Tom Hiddleston",
character: "Loki"
},
{
name: "Clark Gregg",
character: "Agent Phil Coulson"
},
{
name: "Cobie Smulders",
character: "Agent Maria Hill"
},
{
name: "Stellan Skarsgard",
character: "Selvig"
},
{
name: "Samuel L. Jackson",
character: "Nick Fury"
},
{
name: "Gwyneth Paltrow",
character: "Pepper Potts"
},
{
name: "Paul Bettany",
character: "Jarvis (voice)"
},
{
name: "Alexis Denisof",
character: "The Other"
},
{
name: "Tina Benko",
character: "NASA Scientist"
}
];
return Avengers;
});
myApp.controller("AvengersCtrl", function AvengersCtrl(Avengers) {
var avengersCtrl = this;
avengersCtrl.avengers = Avengers;
});
没有控制器名称AveragesCtrl
您声明的控制器名称AvengersCtrl
转换这个
<div ng-controller="AveragesCtrl">
到
<div ng-controller="AvengersCtrl">