javascript - FOR LOOP in Angular Service NOT Working - While Loop Works -
i've worked around problem while loop thought i'd explain here - because seems odd
i tried iterating through string in service using loop, cannot work
when service defined this
.service('xtratxt', function() { var x = 0; var = ""; this.convert = function(srctxt) { this.a = ""; this.x = 0; (this.x=0; this.x++; this.x<srctxt.length) { this.a = ans + "x"; } return ans; }; })
if call in controller
$scope.newvalu = xtratxt.convert("hello");
i should string of x's eg xxxxx instead empty string ""
if change while loop - no problems works treat
anyone know why ?
i no errors in console either. afaik doesn't seem enter loop @ all
this.convert = function (srctxt) { var = "", x = 0, ans = ''; (x = 0; x < srctxt.length; x++) { ans += "x"; } return ans; };
shorter version
var str = 'abcde'; str.replace(/\w/gi, 'x');
Comments
Post a Comment