AngularJS让我告诉我的控制器不是一个功能

时间:2015-05-28 18:14:49

标签: angularjs

当我在浏览器中运行我的应用程序时,控制台告诉我:

  

错误:[ng:areq]参数'FlightListController'不是函数,未定义

'FlightListController'通过“ng-view”

绑定到我的index.html
<div class="container" ng-view="FlightListController"></div>

并在index.html

的末尾相应导入
<script src="app/controller/FlightListController.js"></script>

FlightListController.js内容为:

var app = angular.module("flightlog");

app.controller("Flight", function ($scope, $http) {

$http.get("http://localhost:3000/flights").success(function (response) {
    $scope.flights = response;
}).error(function (err) {
    $scope.error = err;
});

现在我不知道Angular Error想告诉我什么。隐藏在错误背后的Link并没有真正帮助。

2 个答案:

答案 0 :(得分:0)

var app = angular.module("flightlog");

app.controller("FlightListController", ['$scope', '$http', function ($scope, $http) {
  $http.get("http://localhost:3000/flights").success(function (response) {
    $scope.flights = response;
  }).error(function (err) {
    $scope.error = err;
  });
}]);

HTML:

<div class="container" ng-controller="FlightListController">

答案 1 :(得分:0)

如果我没有错,你会告诉他应该使用的控制器:

ng-controller not ng-view

<div class="container" ng-controller="FlightListController">

https://docs.angularjs.org/api/ng/directive/ngController - 文档