0

This is what i have on my controller:

$scope.order = [];
var values = CartService.cart;

angular.forEach(values, function (value, key) {
    $scope.order.push(value.cart_item_name);
});

This part is for the Textarea box:

$scope.payTrans = {
    myOrder: --->equals to something to get all the data
}

And this the html textarea box:

<textarea  style="height: 500px;"
           class="bookingtextareamargin"
           placeholder="Comments"
           ng-model="payTrans.myOrder">
    This where i want to show all the data like :
    Item 1
    item 2
    Item 3
    Item 4
</textarea>
4
  • same idea stackoverflow.com/questions/17586159/… Commented Nov 2, 2016 at 16:58
  • Could look into using something like ngRepeat where you iterate over a collection in the HTML to display your list. Commented Nov 2, 2016 at 16:59
  • if i do that I get [Object, Object, Object, Object] Commented Nov 2, 2016 at 17:31
  • I have no idea how to get the values inside [Object, Object, Object, Object] Commented Nov 2, 2016 at 17:34

1 Answer 1

0

Just use join (js), and \n for newline

$scope.payTrans.myOrder = $scope.order.join('\n');

html:

<div ng-controller="MainCtrl">
 <textarea id="textarea" ng-model="payTrans.myOrder">      
 </textarea>
</div>

controller:

var app = angular.module('myApp', []);

app.controller('MainCtrl', ['$scope', function ($scope) {
    $scope.order = [];
    var values = [{
        cart_item_name: 'item1'
    },
    {
        cart_item_name: 'item2'
    },
    {
        cart_item_name: 'item3'
    },
    {
        cart_item_name: 'item4'
    }    
    ];

    angular.forEach(values, function (value, key) {
        $scope.order.push(value.cart_item_name);
    });

    console.log('s', $scope.order);

    $scope.payTrans = {
        myOrder: $scope.order.join('\n')
        };

}]);
Sign up to request clarification or add additional context in comments.

6 Comments

Its not working i get error TypeError: Cannot set property 'myOrder' of undefined
Hey bro, Thank you So Much Now i will never this now. On this $scope.payTrans = { myOrder: $scope.order.join('\n') }; I was missing $scope.order.join('\n') This is how i was calling it just --- > order then got something like undefined
2 days I was trying to figure this out. Thank you.
Now I see this going to look very messy in the database is there away I could set each item to be on it's Row?
you welcome. if it's helpful for you should can mark this question as answered :). about you last comment - I do not understand what you mean.. what you want to save to database? the text from textarea or from array?
|

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.