user2024080 user2024080 - 5 months ago 14
AngularJS Question

How to split a string and use in `ng-repeat'

From the back-end, I am getting a string as

- that means 2 words together.

Now I need to break them into 2 words and I need to use the
. I created a
to do that. It splits the string into an array with a length of 2, but how to use this in

Here is my code :

<div class="column design">
//app.Phase here is : `construction,apply`
<span ng-repeat="value in activeApp.Phase || commaBreak">{{$index}}</span> //instead of index i would like to show the word.

my filter:


function () {

return function (value) {
if (!value.length) return;

return value.split(',');

What am I doing wrong here?


Here it is:

var myApp = angular.module('myApp',[]);

myApp.controller('MyCtrl', ['$scope', function($scope) {
    $ = "construction,apply";


    function () {

        return function ( value ) {

            if( !value.length ) return;

            return value.split(',');



On html part you need to use the single OR.

<div ng-controller="MyCtrl">
    <p ng-repeat="value in name | commaBreak">{{value}}</p>

Here is the working example: