angularjs - Can't set angular $scope variable from a callback function in Ionic -


i new in angular js. working web sql in test project learning purpose. insert operation working fine. problem when fetch records can't store in $scope.todos=results.rows code is

tx.transaction(sql,[],mycallback) function mycallback(tx,results) {       console.log(results.rows); // shows objects in console        $scope.todos=results.rows; } 

in view todos not working ng-repeat.

it might show of controller, or service. if it's controller make sure included $scope parameter example:

.controller('mycontroller', function ($scope){  })) 

if doing inside service, save in variable inside service, controller "$scope" available include service call variable containing results. helpful if need share results other controllers @ later time.

.service('mydataservice',function(){     var todos;      return {      .... set , functions access variable ...       gettodos: function() {         return todos;       }     };   }); 

and in controller

   .controller('mycontroller', function ($scope, mydataservice){        $scope.todos = mydataservice.gettodos()     })) 

there ways $scope working in service don't think it's great idea.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -