Reputation: 5099
I am trying to retun a value with space added through helper
. but I am not getting the result.
here is my code :
import Ember from 'ember';
export function cardNoDisplay(params/*, hash*/) {
var paramStr = params.toString();
var updatedParams = paramStr.substring(paramStr.length-4);
var reformat = paramStr.replace(/(\d{4})/g, function(match){
return match + Ember.String.htmlSafe("<span>++</span>");
});
return reformat;
}
export default Ember.Helper.helper(cardNoDisplay);
But the result comes like :
<span>3230<span>++</span>4211<span>++</span>5712<span>++</span>8203<span>++</span></span>
What is wrong with my code here?
thanks in advance.
here is the HBS file :
<span class="cs2i-purchase-card-font">
{{card.cardName}}
<span>{{card-no-display card.cardNo}}</span>
</span>
Upvotes: 0
Views: 395
Reputation: 5099
I have updated my filter as like this:
import Ember from 'ember';
export function cardNoDisplay(params/*, hash*/) {
var paramStr = params.toString();
var updatedParams = paramStr.substring(paramStr.length-4);
var reformat = paramStr.replace(/(\d{4})/g, function(match){
return match + "<span> </span>";
});
return Ember.String.htmlSafe(reformat);
}
export default Ember.Helper.helper(cardNoDisplay);
Works fine. thanks to TBieniek
Upvotes: 0
Reputation: 4937
the problem with your snippet is that htmlSafe()
only works for entire strings, not for just parts of a string. instead of applying htmlSafe()
inside the regex replacement function you can return Ember.String.htmlSafe(reformat)
and then it should work as expected.
Upvotes: 1