0

I am getting value from firebase when i push the value to localstorage empty srting is push how to fix it

my code :

    var app = angular.module("bucksbucketapplication", ['firebase', 'ngStorage']);
app.controller("bucksbucket_orders", function ($scope, $firebaseArray, $firebaseObject, $http, $localStorage) {
    var fbvalues = new Firebase("https://qwertyuiop.firebaseio.com/values");
    $scope.syncfromfbvalues = $firebaseArray(fbvalues);
    $scope.$storage = $localStorage.$default({
        "orders": []
    });
    $scope.data = $localStorage.orders;
    $scope.cloneItem = function (syncfromfbvalues) {
        $scope.$storage.orders.push({
            "price": syncfromfbvalues.id
        });
    }
});

and front my end code :

<html ng-app="bucksbucketapplication">

<head>
    <script src="angular.min.js"></script>
    <script src="firebase.js"></script>
    <script src="angularfire.min.js"></script>
    <script src="ngstr.js"></script>
    <script src="script.js"></script>

</head>

<body ng-controller="bucksbucket_orders">

         <li ng-repeat="message in syncfromfbvalues">{{message.greens}} <button class="btn btn-primary" data-ng-click="cloneItem(syncfromfbvalues)">to local</button></li>
</body>

</html>

and My Plunker Demo

2
  • 1
    What is this todo variable you are passing into data-ng-click? also $scope in cloneItem is looking at the $scope of your controller, not the ng-repeat one, so $scope.message is undefined. Commented Oct 8, 2015 at 9:16
  • @Rhumborl hi i update the code can you please look the updated code and plunker too and could you explain in plunker why i"m not getting the value ? Commented Oct 8, 2015 at 9:30

3 Answers 3

1

Hi problem got fixed and this is the Updated Plunker Demo

reason as Rhumborl told in comment i worng send variable and now i got fixed

updated code

data-ng-click="cloneItem(message)" and then in script

$scope.cloneItem = function (message) {
        $scope.$storage.orders.push({
          "price": message.greens
        });
    }
Sign up to request clarification or add additional context in comments.

Comments

0

Intstead of creating reference to $localStorage directly save values to the $localStorage.

$localStorage.orders = []
$scope.cloneItem = function (todo) {
    $localStorage.orders.push({
        "price": $scope.message
    });
}

I faced the same issue when I was working on it and it worked for me this way.

2 Comments

Sorry , it"s not working .. value not sending to local .. did you try the plunker demo ?
hi ng-localstorage working fine but i can"t get the value from "price": $scope.message.greens if i put "price": $scope.message i can get the value as it"s of js script i"m pushing into it "
0

Use promise for asynchronous call. I made some changes into your example. Your messages object is undefined because of asynchronous operation. I added promise, so it's handled now.

Working example: http://plnkr.co/edit/I1Dyn0NmuLMDRYyS8ABU?p=preview

                $scope.getMessages = function () {
                var arr, fbvalues = new Firebase("https://qwertyuiop.firebaseio.com/values");
                arr = $firebaseArray(fbvalues);
                arr.$loaded().then(function (msg) {
                    console.log('Mymsg', msg)
                    return $scope.message = msg;
                });
            };

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.