Ad
Error: Text.replace Is Not A Function In Angularjs Filter, How To Fix This?
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?
Ad
Answer
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";
}
};
}
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad