Angular JS给出了一个未定义的函数错误

时间:2014-11-09 19:52:07

标签: javascript angularjs

我正在编写一个后端应用程序,显示类似于电话簿的列表。我有一些过滤器,它也可以分类和分页。应用程序首先加载所有数据,然后立即完成过滤和分页。我无法弄清楚这里的问题是什么。从在线和我的书一切似乎都没问题。这是我得到的错误:

TypeError: undefined is not a function
at new <anonymous> (http://local.poha.com/js/ang.js:21:10)

var listingsApp = angular.module('listingsApp', []);

listingsApp.controller('pageController', function ($scope, $http) {

    $scope.GetListings();  <--- line 21

    $scope.GetListings = function () {

        //function code here

    }

})

<html ng-app="listingsApp">
...
<body ng-controller="pageController">

    <div class="pagination">Page: <span ng-repeat="page in pages">
        <a href="" ng-click="GoToPage($index)">{{$index + 1}}</a>&nbsp;&nbsp;</span>
    </div>
    <table id="updateTable" width="2000" cellpadding="4" cellspacing="4" border="0">

    ...

        <tr ng-repeat="listing in allListings">
            <td>{{listing.id}}</td>
            <td>{{listing.name}}</td>
            <td>{{listing.address}}</td>
            <td>{{listing.city}}</td>
            <td>{{listing.state}}</td>
    ...

1 个答案:

答案 0 :(得分:0)

在定义之前调用函数$ scope.GetListings()。

尝试:

   $scope.GetListings = function () {
        //function code here
   }
   $scope.GetListings();