Error: [ng:areq] Argument 'approvalCtrl' is not a function, got undefined

Error: [ng:areq] Argument 'approvalCtrl' is not a function, got undefined

我用这样的代码创建了一个项目来显示从数据库到 gridview 的数据

这是给 approval.html

<style type="text/css">
    .auto-style4 {
        width: 260px;
        height: 50px;
    }

    .auto-style5 {
        width: 292px;
        height: 50px;
    }

    .auto-style6 {
        width: 850px;
        height: 50px;
    }

    .auto-style13 {
        width: 260px;
        height: 54px;
    }

    .auto-style14 {
        width: 292px;
        height: 54px;
    }

    .auto-style15 {
        width: 850px;
        height: 54px;
    }
</style>
<style>
    .panel-default > .panel-heading {
        color: #f5ffff;
        background-color: #6d1014;
    }

    .auto-style20 {
        width: 260px;
        height: 64px;
    }

    .auto-style21 {
        width: 292px;
        height: 64px;
    }

    .auto-style22 {
        width: 850px;
        height: 64px;
    }

    .auto-style23 {
        width: 260px;
        height: 10px;
    }

    .auto-style25 {
        width: 129px;
    }

    .auto-style26 {
        width: 292px;
        height: 10px;
    }
</style>




<div class="row">
    <div class="col-md-1"></div>
    <div class="col-md-10">

        <div class="panel panel-default" style="width: 900px;">
            <div class="panel-heading">
                <h4 class="panel-title">
                    <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo">
                        Approval
                    </a>
                </h4>
            </div>

            <div id="collapseTwo" class="collapse in">
                <div class="panel-body">
                    <div class="row">
                        <div class="col-md-1">
                            <table>
                                <tr>
                                    <td></td>
                                </tr>
                            </table>
                        </div>

                        <div class="col-lg-10">
                            <form class="form-horizontal">
                                <div class="form-group">

                                    <br />
                                    <!--ROW 1 = Period -->
                                    <div class="row">
                                        <div class="col-md-1"></div>
                                        <div class="col-md-2">
                                            <label for="labelPeriod" class="control-label">Period</label>
                                        </div>
                                        <div class="col-md-4">
                                            <input id="txtOldDate" max="txtNewDate" type="date" class="datepicker" />
                                        </div>
                                        <div class="col-md-1">
                                            <label for="labelTo" class="control-label">To</label>
                                        </div>
                                        <div class="col-md-4">
                                            <input id="txtNewDate" min="txtOldDate" type="date" class="datepicker" />
                                        </div>
                                        <div class="col-md-4"></div>
                                    </div>
                                    <br />

                                    <!--ROW 2 = Department-->
                                    <div class="row">
                                        <div class="col-md-1"></div>
                                        <div class="col-md-2">
                                            <label for="labelDepartment" class="control-label">Department</label>
                                        </div>
                                        <div class="col-md-5">
                                            <div class="side-by-side clearfix">
                                                <div class="dropdown">
                                                    <select id="ddlDepartment" class="form-control">
                                                        <option>EDP Department</option>
                                                        <option>Departemen 2</option>
                                                        <option>Departemen 3</option>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-5"></div>
                                    </div>

                                    <!--ROW 3 = Employee-->
                                    <div class="row">
                                        <div class="col-md-1"></div>
                                        <div class="col-md-2">
                                            <label for="labelEmployee" class="control-label">Employee</label>
                                        </div>
                                        <div class="col-md-5">
                                            <div class="side-by-side clearfix">
                                                <div class="dropdown">
                                                    <select id="ddlManagerApproval" class="form-control">
                                                        <option>Manager 1</option>
                                                        <option>Manager 2</option>
                                                        <option>Manager 3</option>
                                                    </select>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-md-5"></div>
                                    </div>
                                    <br />

                                    <!--ROW 4 = Button Show Data-->
                                    <div class="row">
                                        <div class="col-md-1"></div>
                                        <div class="col-md-2">
                                            <input id="btnSubmit" type="button" class="btn btn-primary" value="Show" />
                                        </div>
                                        <div class="col-md-9"></div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!--ROW 5 = Gridview-->

    <div class="row">
        <div class="col-md-1"></div>
        <div class="col-md-2"></div>
        <div class="col-md-5"></div>
    </div>

    <br />

    <div ng-controller="approvalCtrl" class="row">
        <div class="col-md-1"></div>
        <div class="col-md-10">
            <table class="table table-bordered table-hover">
                <tr style="background-color:#6d1014; color:#FFFFFF">
                    <th>Ticket Number</th>
                    <th>Requester Account</th>
                    <th>Category</th>
                    <th>Sub Category</th>
                    <th>Subject</th>
                    <th>Body</th>
                    <th>FIle Name</th>
                    <th>Assigned To</th>
                </tr>
                <tbody ng-repeat="e in requestList">
                    <tr>
                        <td>{{e.TICKET_NUMBER}}</td>
                        <td>{{e.REQUESTER}}</td>
                        <td>{{e.CATEGORY}}</td>
                        <td>{{e.SUBCATEGORY}}</td>
                        <td>{{e.SUBJECT}}</td>
                        <td>{{e.BODY}}</td>
                        <td>{{e.CATEGORY}}</td>
                        <td>{{e.FILE_NAME}}</td>
                        <td>{{e.ASSIGNED_TO}}</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

这是approvalCtrl.js

(function (app) {
    'use strict';

    app.controller('approvalCtrl', function ($scope, GetDataService) {
        function getAllDataRequest() {
            GetDataService.getRequestData().then(function (emp) {
                $scope.requestList = emp.data;
            }, function (error) {
                alert('failed to fetch data');

            });
        }

    })(angular.module('myapplication'));
});

这是approvalController.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MyApplication.Service.Controllers
{
    public class ApprovalController : Controller
    {
        // GET: Approval
        public ActionResult Index()
        {
            return View();
        }

        public JsonResult GetAll()
        {
            List<TRN_SERVICE_REQUEST> reqdata = new List<TRN_SERVICE_REQUEST>();
            using (RREntities ed = new RREntities())
            {
                reqdata = ed.TRN_SERVICE_REQUEST.ToList();
                return new JsonResult { Data = reqdata, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
            }
        }
    }
}

这是app.js

(function () {
    'use strict';

    var app = angular.module('myapplication', ['common.core', 'common.ui'])
        .config(config)
        .run(run);

    config.$inject = ['$routeProvider'];
    function config($routeProvider) {
        $routeProvider
            .when("/", {
                templateUrl: "scripts/spa/home/index.html",
                controller: "indexCtrl"
            })
            .when("/entry", {
                templateUrl: "scripts/spa/entry/entry.html",
                controller: "entryCtrl"
            })
            .when("/approval", {
                templateUrl: "scripts/spa/approval/Approval.html",
                controller: "approvalCtrl"
            });

    }

    run.$inject = ['$rootScope', '$location', '$cookieStore', '$http'];
    function run($rootScope, $location, $cookieStore, $http) {
        // handle page refreshes
        $rootScope.repository = $cookieStore.get('repository') || {};
        if ($rootScope.repository.loggedUser) {
            $http.defaults.headers.common['Authorization'] = $rootScope.repository.loggedUser.authdata;
        }

        $(document).ready(function () {
            $(".fancybox").fancybox({
                openEffect: 'none',
                closeEffect: 'none'
            });

            $('.fancybox-media').fancybox({
                openEffect: 'none',
                closeEffect: 'none',
                helpers: {
                    media: {}
                }
            });

            $('[data-toggle=offcanvas]').click(function () {
                $('.row-offcanvas').toggleClass('active');
            });
        });
    }

})();

页面结果如图所示 Result Page

为什么得到错误的结果不是一个函数?

提前致谢

您需要在 HTML

中定义应用
<div ng-app = "myapplication"></div>

我觉得你把自调用函数写错了。论点没有正确放置。应该在下面一行。

(function (app) {
    'use strict';

    app.controller('approvalCtrl', function ($scope, GetDataService) {
        function getAllDataRequest() {
            GetDataService.getRequestData().then(function (emp) {
                $scope.requestList = emp.data;
            }, function (error) {
                alert('failed to fetch data');

            });
        }

    });
})(angular.module('myapplication'));