admin管理员组

文章数量:1391934

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 .

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 asked Sep 20, 2014 at 8:14 Himanshu BhuyanHimanshu Bhuyan 3062 gold badges8 silver badges20 bronze badges 2
  • You can do by creating custom filter.. – Jay Shukla Commented Sep 20, 2014 at 8:16
  • 1 Possible duplicate of How to split a string with angularJS – Dave DuPlantis Commented Jun 15, 2017 at 18:15
Add a ment  | 

2 Answers 2

Reset to default 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

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

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

本文标签: javascriptHow to split string using angular jsStack Overflow