How to create function history and add to datalist

Hi,
i have a big problem.
I have file transferCtrl.js and i want create function which will show only persons to which the bank transfer was made before.
I tries to pass data to a new table, but i can’t to this.
And this data history transfer i want to show in datalist. Please help me, i’m newbie.

This is my transferCtrl.js

app.controller('TransfersCtrl', [ '$http', 'common', function($http, common) {
    console.log('Controller TransfersCtrl start')
    var ctrl = this

    ctrl.formatDateTime = common.formatDateTime

    ctrl.history = []

    ctrl.recipients = []
    ctrl.recipient = null

    ctrl.transfer = {
        delta: 1.00
    }

    ctrl.amount = 0
    
    var refreshHistory = function() {
        $http.get('/transfer').then(
            function(res) {
                ctrl.history = res.data
                $http.delete('/transfer').then(
                    function(res) { ctrl.amount = res.data.amount },
                    function(err) {}
                )
            },
            function(err) {}    
        )
    }

    refreshHistory()

    ctrl.doTransfer = function() {
        $http.post('/transfer?recipient=' + ctrl.recipient._id, ctrl.transfer).then(
            function(res) {
                refreshHistory()
            },
            function(err) {}
        )
    }

    $http.get('/personList').then(
        function(res) {
            ctrl.recipients = res.data
            ctrl.recipient = ctrl.recipients[0]
        }, 
        function(err) {
            ctrl.recipients = []
            ctrl.recipient = null
        }
    )
}])

and this is my This is my transferView.html

<table class="table table-stripped">
    <tr">
        <th>date</th>
        <th>sender</th>
        <th>recipient</th>
        <th>amount before/th>
        <th>transfer</th>
        <th>amount after</th>
    </tr>
    <tr ng-repeat="transfer in ctrl.history">
        <td ng-bind="ctrl.formatDateTime(transfer.date)"></td>
        <td ng-bind="transfer.senderFirstName+' '+transfer.senderLastName"></td>
        <td ng-bind="transfer.recipientFirstName+' '+transfer.recipientLastName"></td>
        <td ng-bind="transfer.amount_after - transfer.delta"></td>
        <td ng-bind="transfer.delta"></td>
        <td ng-bind="transfer.amount_after"></td>
    </tr>
</table>

<br/><br/>

<div class="panel panel-default">
    <div class="panel-heading">transfer</div>
    <div class="panel-body">
        <form class="form form-inline">
            <select class="form-control" ng-model="ctrl.recipient" ng-options="option.firstName+' '+option.lastName for option in ctrl.recipients track by option._id">
            </select>
            <input class="form-control" type="number" ng-model="ctrl.transfer.delta"/>
            <button class="btn btn-default" ng-click="ctrl.doTransfer()" ng-disabled="ctrl.transfer.delta > ctrl.amount">transfer</button>
        </form>
    </div>
</div>

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

1 Like