Reputation: 3090
I created a method that appends a string if a checkbox is checked, and if not checked, it should remove the value from the string using the replace()
method
The code for the method:
current_search : string = "";
generateLink(e, n) {
if(e.checked){
this.current_search = this.current_search + " " + n + ",";
console.log(this.current_search);
} else {
this.current_search.replace(n, '');
console.log(this.current_search);
}
}
Nothing gets updated on the string when the checkbox is unchecked. When it is checked, the string is appended with whatever 'n' is as that is being passed into the method.
Upvotes: 2
Views: 10621
Reputation: 1145
actually replace methods returns the new string with some or all matches of a pattern replaced by a replacement, what your doing is not saving the return value of replace method
let a = "how ur doin";
a = a.replace('ur','');
console.log(a);
try by saving return value of replace method by
this.current_search = this.current_search.replace(n, '')
Upvotes: 4