Reputation: 3750
in the angular i trying to use filter in angular to replace some string with another word that it can find, i already try many example, i think my code is just missing something, but i can't figure it out. Here is my code :
here is my app.js
app.filter('filterStatus', function () {
return function (text) {
if(text == 1){
return str = text.replace(/1/g, "Waiting");
} else if (text == 2) {
return str = text.replace(/2/g, "On Process");
} else if (text == 3) {
return str = text.replace(/3/g, "On The Way");
} else if (text == 4) {
return str = text.replace(/4/g, "Delivered");
} else if (text == 5) {
return str = text.replace(/5/g, "Expired");
}
};
});
i going to replace "1" with "Waiting" word, here is my html page
<tr ng-repeat-start="siheaders in singleID.siheader">
<td>{{siheaders.status | filterStatus}}</td>
</tr>
but it give me these "Error: text.replace is not a function" error when i use firebug to debug it, what am i missed here?
Upvotes: 0
Views: 1286
Reputation: 14423
There's really no need to do any string replacement.
app.filter('filterStatus', function () {
return function (text) {
if(text == 1){
return "Waiting";
} else if (text == 2) {
return "On Process";
} else if (text == 3) {
return "On The Way";
} else if (text == 4) {
return "Delivered";
} else if (text == 5) {
return "Expired";
}
};
}
Upvotes: 1