为什么我的ng-repeat更新?

时间:2015-05-21 00:10:27

标签: javascript angularjs

我对角度很新。这是我第一次涉足它。

我有一个非常基本的应用程序,通过一些行重复,这些行被过滤。当我将新数据推送到我的对象中时,即使我期望它也不会出现在我的表中。

有什么想法吗?

UonApp.controller('CtrlFees', ['$scope', function($scope) {

    $scope.student = window.location.hash.substring(1);
    $scope.currencySymbol = '£';


    $scope.addFee = function() {
        $scope.fees.push = { id: 4, studentId: parseInt($scope.student), paymentAmount: $scope.newAmount, paymentDate: '2015-05-19' }
        $scope.newAmount = '';

        console.table($scope.fees);
    }

    $scope.fees = [
        { id: 1, studentId: 3, paymentAmount: 9000, paymentDate: '2014-06-03' },
        { id: 2, studentId: 2, paymentAmount: 9000, paymentDate: '2014-03-08' },
        { id: 3, studentId: 2, paymentAmount: 9000, paymentDate: '2014-05-04' }
    ];

    console.table($scope.fees);

}]);

我的观点:

<table>
                    <thead>
                        <tr>
                            <th>Payment Amount</th>
                            <th class="right">Payment Date</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr ng-repeat="fee in filteredFees = (fees | orderBy: 'paymentDate' | filter:{studentId:student})">
                            <td>{{fee.paymentDate | date:'mediumDate'}}</td>
                            <td class="right">{{fee.paymentAmount | currency:currencySymbol}}</td>
                        </tr>
                        <tr>
                            <th class="right">Add Fee Payment</th>
                            <td class="right"><input type="number" placeholder="Amount" ng-model="newAmount"> <input type="button" value="Add" ng-click="addFee()"></td>
                        </tr>
                        <tr>
                            <th class="right">Total</th>
                            <td class="right strong"></td>
                        </tr>
                    </tbody>
                </table>

我还需要汇总列出的付款金额,包括添加的行。

1 个答案:

答案 0 :(得分:1)

我认为您的问题出在$scope.addFee

$scope.fees.push = { id: 4, studentId: parseInt($scope.student), paymentAmount: $scope.newAmount, paymentDate: '2015-05-19' }

您可能意味着$scope.fees.push(...)