Answer the question
In order to leave comments, you need to log in
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,
})
.success(function(param){
console.log(param);
$scope.dataTable = param;
})
.error(function() {
console.log('error');
});
$scope.getData = function () {
angular.element('#dateStart').triggerHandler('change');
var data = {
start: $scope.dateStart,
finish: $scope.dateFinish,
transactions: $scope.transactions,
count: $scope.count,
};
console.log(data);
$http.post('/url', data)
.success(function(param){
console.log(param);
})
.error(function() {
console.log('error');
});
$scope.count +=20;
};
});
<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>
<div class="form-group">
<label for="exampleInputName2">Дата окончания:</label>
<input type="text" class="form-control date" id="dateFinish" placeholder="" ng-model="dateFinish" >
</div>
<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>
</select>
</div>
<div class="form-group">
<button name="submit" value="filter" class="btn-search-form" aria-labelledby="">Искать</button>
</div>
</div>
<table class="table table-striped table-transactions">
<thead>
<tr>
<th>Время</th>
<th>Бонус</th>
<th>№ чека</th>
<th>Сумма</th>
<th>Касса</th>
<th>Тип транзакции</th>
<th>Ответственный</th>
<th>№ карты</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in dataTable">
<td>{{item.time}}</td>
<td>{{item.bonus}}</td>
<td>{{item.ticket}}</td>
<td>{{item.sum}}</td>
<td>{{item.kassa}}</td>
<td>{{item.type}}</td>
<td>{{item.access}}</td>
<td>{{item.card}}</td>
</tr>
</tbody>
</table>
</form>
<button class="update-table">
<span class="glyphicon glyphicon-repeat"></span>
</button>
</div>
Answer the question
In order to leave comments, you need to log in
!!!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
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 questionAsk a Question
731 491 924 answers to any question