Im trying to convert an array of Strings, to a single string. I made a quick plunker of what I need in basic terms:
https://plnkr.co/edit/t2KeZJ8yOtDo2KxDQuzD?p=preview
In the app Im working on I need to use two different controllers and I created a factory for the controllers to share data, so I set the example up like that.
Here is the function I am trying to use to loop the array and add to a scope variable, with CherryPick being the array:
cherryCtrl.CherryPick = CherryPick.list;
cherryCtrl.string = cherryCtrl.output;
cherryCtrl.runString = function createString(array) {
angular.forEach(cherryCtrl.CherryPick, function (object) {
angular.forEach(object, function (value, key) {
cherryCtrl.output += value + ' ';
console.log(cherryCtrl.output);
});
});
return cherryCtrl.output;
}
the console for output gives:
undefinedHello World
undefinedHello World object:5
undefinedHello World object:5 Goodbye World
undefinedHello World object:5 Goodbye World object:8
Which is confusing.
I took the idea for the loop from here:
Any pointer would be mucho appreciated
cherryCtrl.outputcherryCtrl.CherryPicklook like?array.join(' ')?