javascript - How to update my $scope after adding new elements? -


i have problem controller. use ionic (angular) , js-data. when add new item via additem() when see if reload page via f5.

here code:

.controller('fooctrl', function($scope, $ionicplatform, foo) {     $ionicplatform.ready(function() {         foo.findall().then(function (items) {             $scope.items = items;         });     });      $scope.item = {};     $scope.additem = function () {         foo.create({ name: $scope.item.name });     }; }) 

what have see new element withous first pressing f5 in browser window?

you creating item , updating database. not updating $scope.items. push item $scope.items or can call code after creating. update $scope.items

foo.findall().then(function (items) {                 $scope.items = items;             }); 

use code:

.controller('fooctrl', function($scope, $ionicplatform, foo) {     $ionicplatform.ready(function() {         foo.findall().then(function (items) {             $scope.items = items;         });     });      $scope.item = {};     $scope.additem = function () {         foo.create({ name: $scope.item.name });         $scope.items.push({ name: $scope.item.name });     }; }) 

or

.controller('fooctrl', function($scope, $ionicplatform, foo) {     $ionicplatform.ready(function() {         foo.findall().then(function (items) {             $scope.items = items;         });     });      $scope.item = {};     $scope.additem = function () {         foo.create({ name: $scope.item.name });            foo.findall().then(function (items) {                 $scope.items = items;             });     }; }) 

Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -