3

仍然得到相同的错误Argument 'AveragesCtrl' is not a function, got undefined我已经尝试了类似问题提供的所有解决方案,但没有运气,知道我做错了什么吗?

<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;
    }); 
4

1 回答 1

2

没有控制器名称AveragesCtrl

您声明了一个控制器名称AvengersCtrl

转换这个

<div ng-controller="AveragesCtrl">

<div ng-controller="AvengersCtrl">
于 2015-11-26T03:04:38.283 回答