0

我对角度很陌生,我一生都无法弄清楚这段代码有什么问题。我很乐意根据需要提供更多代码。

问题是没有发生任何角度动作。该表没有被填充,并且没有任何按钮执行任何操作。http get 永远不会到达我的服务器。所以,我想知道是否有人不介意快速浏览一下并让我知道我是否犯了一个愚蠢的错误。

这是我的角度代码:

function locateController($scope, $http) {
            $scope.init = function () {
                $http.get('@(Url.Action<WorkorderController>(c => c.GetLocateNumbers(Model.Id)))').success(function (data) {
                    $scope.model = data;
                    $scope.locateNumber = $scope.locateNumbers();

                    $("#loading").css('display', 'none');
                    $("#ctrl").css('visibility', 'visible');
                    $scope.master = angular.copy($scope.model);
                });
            };

            $scope.init();

            $scope.reset = function () {
                if (confirm('Are you sure you want to discard all your changes?')) {
                    $scope.model = angular.copy($scope.master);
                    $(".selected").removeClass("selected");

                    $scope.locateNumber = $scope.locateNumbers();
                };
            };

            $scope.removeLocate = function (remove) {
                if (confirm('Are you sure you want to remove this location number?')) {
                    var oldLines = $scope.locateNumber;
                    $scope.labor = [];
                    angular.forEach(oldLines, function (line) {
                        if (line != remove) $scope.locateNumber.push(line);
                    });
                }
            };

            $scope.locateNumbers = function () {
                if (!$scope.model) {
                    return null;
                }

                var lines = [];
                angular.forEach($scope.model, function (item) {
                    if (item.IsActive) {
                        lines.push(item);
                    }
                });
                return lines;
            };

            $scope.addLocateLine = function () {
                $scope.locateNumber.push({
                    locationNum: ''
                });
            };

            $scope.dirty = function () {
                if ($scope.model === undefined) {
                    return false;
                }
                var isDirty = !angular.equals($scope.locateNumber, $scope.master.locateNumbers);
                if (isDirty) {
                    $scope.notice = null;
                }
                return isDirty;
            };

            $scope.save = function () {
                $scope.model.Size = $scope.locateNumber.length;
                $scope.model.locateNumbers = $scope.locateNumber;

                $http({
                    method: 'post',
                    url: '@(Url.Action<WorkorderController>(c => c.AssignLocate(Model.Id,null)))',
                    headers: {
                        "Content-Type": 'application/json',
                        Accepts: 'application/json'
                    },
                    data: { wo: $scope.model }
                }).success(function (data, status, headers, config) {
                    $scope.init();
                }).error(function (data, status, headers, config) {
                    alert('An error has occurred. Please try again later or contact an administrator');
                });
            };
        };

这是HTML:

<div class="modal hide" id="assignLocate" data-ng-controller="locateController">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal">×</button>
        <h3 class="addRow">Locate Number <button type="button" class="btn btn-warning btn-mini" data-ng-click="addLocateLine()">Add</button></h3>
    </div>
    <div>
        <div class="span3 offset1">
            <table cellpadding="0" cellspacing="25" border="0" class="table" id="locateNumbers">
                <thead>
                    <tr>
                        <th>Locate Number</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                    <tr ng-repeat="num in locateNumber">
                        <td>
                            <ng-form name="LocateNum">
                                <input type="text" ng-model="num.LocateNum" class="span2" required name="Input"/>
                                <span class="alert-error" ng-show="LocatenNum.Input.$error.required"><strong>*Required</strong></span>
                            </ng-form>
                        </td>
                        <td>
                            <button class="btn btn-mini btn-danger" ng-click="removeLocate(line)">Remove</button>
                        </td>
                    </tr>
                </tbody>
            </table>
            <br /><br />
            <div>
                <div class="span3" style="padding-bottom:25px; margin-left: 0px">
                    <button type="button" class="btn btn-inverse" ng-click="reset()" ng-disabled="!dirty()">Reset</button>
                    <button type="button" class="btn btn-primary pull-right" ng-disabled="form.$invalid" ng-click="save()" ng-disabled="!dirty()">Save</button>
                </div>
            </div>
        </div>
    </div>
</div>

这是一个 js 小提琴:http: //jsfiddle.net/exmMY/

4

1 回答 1

1

以下是我注意到的问题:

  1. HTML 中没有“ng-app”。
  2. locateNumbers函数有时会返回null,但代码的其他部分期望locateNumber是数组。

我没有排除更多功能。更改您的示例可以在这里找到:http ://plnkr.co/edit/A52VmYLznpNqMLq4XLK0?p=preview

于 2013-02-05T16:36:15.613 回答