(I’ll try to be as clear as I can be. Let me know if this is a silly question, I’m still a newbie.)
So I have a code that should insert/update informations in a db and then display it for the user. The thing is that it doesn’t display what has been inserted/updated automatically (like it should), I have to leave the page and then re-enter for it to show. I’m not sure what I’m doing wrong. help?
here is my controller:
> ` $scope.onUpdate = function(item){
> $scope.dados.quantidade = item.quantidade;
> $ionicPopup.show({
> title: 'Atualização de Água',
> cssClass: 'popup',
> scope: $scope,
> template: "<ion-radio ng-model='dados.quantidade' value='100'>100 ml</ion-radio><ion-radio ng-model='dados.quantidade' value='200'>200 ml</ion-radio><ion-radio ng-model='dados.quantidade' value='300'>300 ml</ion-radio><ion-radio ng-model='dados.quantidade' value='400'>400 ml</ion-radio><ion-radio ng-model='dados.quantidade' value='500'>500 ml</ion-radio>",
> buttons:[
> {text: "Ok",
> onTap: function(e){
> item.quantidade = $scope.dados.quantidade;
> var query = "UPDATE agua SET quantidade='"+item.quantidade+"' WHERE id="+item.id+"";
> localDB.transaction(function(transaction) {
> transaction.executeSql (query, [], function (transaction, res) {
> grafico($scope.dados.meta);
> });
> })
> }},
> {text: "Cancel"}
> ]
> });
> $ionicListDelegate.closeOptionButtons();
> }
> $scope.onInsert = function(){
> var hora = $filter('date')(new Date(),'HH:mm');
> $ionicPopup.show({
> title: 'Quantidade de Água (ml)',
> scope: $scope,
> template: "<ion-radio ng-model='dados.quantidade' value='100'>100 ml</ion-radio><ion-radio ng-model='dados.quantidade' value='200'>200 ml</ion-radio><ion-radio ng-model='dados.quantidade' value='300'>300 ml</ion-radio><ion-radio ng-model='dados.quantidade' value='400'>400 ml</ion-radio><ion-radio ng-model='dados.quantidade' value='500'>500 ml</ion-radio>",
> buttons:[
> {text: "Ok",
> onTap: function(e){
> var query = "INSERT INTO agua ('data','hora','quantidade') VALUES (date('now'),'"+hora+"','"+$scope.dados.quantidade+"')";
> localDB.transaction(function(transaction) {
> transaction.executeSql (query, [], function (transaction, res) {} ) });
>
> localDB.transaction(function(transaction) {
> transaction.executeSql ("SELECT MAX(id) AS id FROM agua", [], function (transaction, res) {
> var id = res.rows.item(0).id;
> grafico($scope.dados.meta);
> $scope.dados.unshift({ hora: hora, quantidade: $scope.dados.quantidade, id: id });
> })
> })
> }},
> {text: "Cancel"}
> ]
> });
> $ionicListDelegate.closeOptionButtons();
> };`
here is my html
> <h4 class="titulo">Consumo do Dia</h4>
> <canvas id="bar" class="chart chart-bar" chart-data="data" chart-labels="labels" chart-options="{showTooltips: true}" chart-colours="colours" chart-legend="false" chart-series="series"></canvas>
> <div class="item item-divider">Meus Registros {{dados.data}}</div>
> <ion-list>
> <ion-item ng-repeat="item in dados track by $index" class="item">
> <div class="row">
> <div class="col"><i class="icon ion-waterdrop"></i>
> <ion-option-button class="button button_opt button-calm" ng-click="onUpdate(item)">Edit</ion-option-button>
> <ion-option-button class="button button_opt button-assertive" ng-click="onDelete(item)">Del</ion-option-button>
> {{item.quantidade}} ml</div>
> <div class="col"><span class="item-note">{{item.hora}}</span></div>
> </div>
> </ion-item>
> </ion-list>
> </div>
> </ion-content>
> <ion-footer-bar align-title="left" class="footer">
> <p class="title">Cadastrar água</p>
> <div class="buttons">
> <button class="button button-icon icon ion-ios-plus-empty" ng-click="onInsert()" disable="meta == true"> </button>
> </div>
> </ion-footer-bar>