0

I am new in angular js.

my array -

"cards":[
"xxx Bank Credit Card",
"yyy Bank Debit Card"
],

what i am tring get only xxx adn yyy or Credit and Debit from the string .I am using angular js 1.2.23 .

2

2 Answers 2

1

Try this

angular.module('myModule', [])
    .filter('split', function() {
        return function(input, splitChar, splitIndex) {
            // do some bounds checking here to ensure it has that index
            return input.split(splitChar)[splitIndex];
        }
    });

Use in view like

{{test | split(',',0)}}

Ref - See here

Sign up to request clarification or add additional context in comments.

3 Comments

if I have to add this split function on ng-model instead of {{ }} expression, then how to add filter on ng-model parameter
You can not use filter with ng-model. I think you want to apply filter on your ng-model value which you can achieve with custom $watch on that model.
ya I can not use it on ng-model..... but my question is how to use it on ng-model value? in controller? using $filter? or can we use?
0

You can even use default Filter of Angular Js " limitTo() " . it is very helpful but not a splitter , https://docs.angularjs.org/api/ng/filter/limitTo

in your case you can use it like {{cards[0] | limitTo(3) }} =xxx

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.