olafars2016-02-26 11:07:58
olafars, 2016-02-26 11:07:58

Angular data not updating?

Good day!
There is this code:

angular.module("transactionsApp", [])
        .controller("formCtrl", function ($scope, $http) {

            $scope.count = 0;

            var date = new Date();
            var prevDate = new Date();
            prevDate.setDate(prevDate.getDate()-7);/*берем время на неделю назад*/
            $scope.dateStart = prevDate.getFullYear() + '-' + (prevDate.getMonth() + 1) + '-' + prevDate.getDate();
            $scope.dateFinish = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
            $scope.transactions = 0;

            $http.post('/cabinet/transactions/getTransactions', {
                    start: $scope.dateStart,
                    finish: $scope.dateFinish,
                    transactions: $scope.transactions,
                    count: $scope.count,
                    $scope.dataTable = param;
                .error(function() {

            $scope.getData = function () {
                var data = {
                    start: $scope.dateStart,
                    finish: $scope.dateFinish,
                    transactions: $scope.transactions,
                    count: $scope.count,
                $http.post('/url', data)
                    .error(function() {
                $scope.count +=20;

and this is the html:
<div class="transaction" ng-controller="formCtrl">
    <form ng-submit="getData(e)">
    <div class="button-search">
        <div class="form-group">
            <label for="exampleInputName2">Дата начала:</label>
            <input type="text" class="form-control date" id="dateStart" placeholder="" ng-model="dateStart" >
        <div class="form-group">
            <label for="exampleInputName2">Дата окончания:</label>
            <input type="text" class="form-control date" id="dateFinish" placeholder="" ng-model="dateFinish" >
        <div class="form-group">
            <label for="fm-8">Тип транзакции</label>
            <select name="transaction_type" class="form-control" id="transactions" ng-model="transactions" aria-labelledby="fm-7">
                <option value="0">Все</option>
                <option value="1">Начисление стартового бонуса покупателю</option>
                <option value="2">Ручное начисление бонусов на карту покупателя</option>
                <option value="3">Ручное списание бонусов с карты покупателя</option>
                <option value="4">Начисление бонусов на карту покупателя</option>
                <option value="5">Списание бонусов с карты покупателя</option>
                <option value="6">Сгорание бонусов на карте покупателя</option>
                <option value="7">Начисление Дружеского Бонуса</option>
        <div class="form-group">
            <button name="submit" value="filter" class="btn-search-form" aria-labelledby="">Искать</button>
    <table class="table table-striped table-transactions">
                <th>№ чека</th>
                <th>Тип транзакции</th>
                <th>№ карты</th>
            <tr ng-repeat="item in dataTable">
    <button class="update-table">
        <span class="glyphicon glyphicon-repeat"></span>

the problem is that when the data is changed, the update of $scope.dateStart and $scope.dateFinish does not work, because there is no change in the value itself, it is set through the datapicker of the bootstrap framework, i.e. when you click on the input, a window with a date selection pops up, I choose, the text in the field changes, but in fact, the value itself has not changed and initially remains the same as it was set by default. If you change the date manually without a datapicker, then the connection works out and changes occur, the data changes. I tried to simulate the change event, but this did not work at the moment, what could be the problem, where did I go wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
MNB, 2016-02-26

!!!Date must be a date, not a string!!!
For the correct operation of the datepicker in anular, you will have to conjure with events. I would advise https://angular-ui.github.io/bootstrap/#/datepicker

lega, 2016-02-26

1) It is best to use a ready-made directive for this, it should be under bootstrap.
2) With dates it is better to operate with the Date type and not in string.
3) triggerHandler is an angular cartoon, make a normal js event - new Event('change') and dispatch it to the element, then the model should react.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question