0

ng-bind is not binding data if I assign a var for it. Why?

var output = $scope.output;
      output = JSON.stringify(txt);

Plnkr : --> http://plnkr.co/edit/srYQnpHudt7gfeOXN1ff?p=preview

1
  • did my answer solve your issue. If so please mark it as the correct answer to close the question. Thanks Commented Nov 6, 2015 at 5:28

2 Answers 2

2

http://plnkr.co/edit/3VRAlVS63bqSXxTd5l0N?p=preview

Is this what you wanted:

    app.controller('cCtrl', function($scope) {
    $scope.generate = function () {
    var txt  = $scope.objInput;

     var output = JSON.stringify(txt);
       $scope.output = output ;
    };

});// Fin qCtrl
Sign up to request clarification or add additional context in comments.

3 Comments

yes but i want to use it like this. var output = $scope.output; output = JSON.stringify(txt);
You just overwrote the local var value output. It seems like maybe you think setting that value will set $scope.output? That is not how things work.
Do you want to display the output or just use it within the generate method? Seems like you are just creating variables for no reason.
0

You didn't assign the variable to ng-bind, I have changes this way, here the objInput is assigned txt and then its converted to string and then stored to output variable and then assigned scope variable output.

$scope.generate = function (){ var txt = $scope.objInput; var output = JSON.stringify(txt); $scope.output = output; };

Hope this helps.

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.