Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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 .

share|improve this question
    
You can do by creating custom filter.. –  Jay Shukla Sep 20 '14 at 8:16

3 Answers 3

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

share|improve this answer

you can just do it using pure js

str.replace(' Bank', '').replace(' Card', '');
share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.