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

Angular JS is Giving an Undefined Function Error

本文关键字:一个 未定义 错误 函数 JS Angular      更新时间:2023-09-26

我正在编写一个后端应用程序,它显示类似于电话簿的列表。我有一些过滤器,它排序,以及分页。该应用程序首先加载所有数据,然后过滤和分页基本上立即完成。我搞不清楚这里出了什么问题。从网上和我的书一切似乎都很好。这是我得到的错误:

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>
    ...

在定义函数$scope.GetListings()之前,您可以调用它。

尝试:

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