javascript - Convert array to string in AngularJS -


im trying convert array of strings, single string. made quick plunker of need in basic terms:

https://plnkr.co/edit/t2kezj8yotdo2kxdquzd?p=preview

in app im working on need use 2 different controllers , created factory controllers share data, set example that.

here function trying use loop array , add scope variable, cherrypick being 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 output gives:

undefinedhello world   undefinedhello world  object:5   undefinedhello world  object:5  goodbye world   undefinedhello world  object:5  goodbye world  object:8  

which confusing.

i took idea loop here:

array string angular

any pointer mucho appreciated

so, main problem code

cherrypick.list.push({     snippet }); 

in old browser not implement es6 code raise exception: syntax error, in new standard

{ snippet } 

is shorthand property names (es6), push list not string object - {snippet: "snippetvalue"}.

after binding view, in object added special angular property $$hashkey value object:5, that's why see unexpected string in output.

for solution can add string instead object,

cherrypick.list.push(// note: without curly brackets     snippet ); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -