1

I have tried to filter blank string item from ng-repeat. But didn't succeeded. Can someone please help me at this.

JSFiddel Link

HTML Code:

<div ng-app ng-controller="myCtrl">
    <ul>
        <li ng-repeat="detail in details | filter: filter2 ">
            <p>{{detail.name}}</p>
        </li>
    </ul>
</div>

JS Code:

function myCtrl($scope) {
    $scope.details = [{
        name: 'Bill',
        shortDescription: null
    }, {
        name: 'Sally',
        shortDescription: 'A girl'
    },{
        name: 'Tally',
        shortDescription: ''
    }];
}

function filter2(detail){
    if (item.shortDescription.length == 0){
        return true;
    }
    else{
        return false;
    }
}

Expected Result:

/*
Expected Result

Bill
Sally
*/
1
  • Your fiddle does not seem to work... Commented Sep 11, 2015 at 9:19

1 Answer 1

2
<div ng-app ng-controller="myCtrl">
    <ul>
        <li ng-repeat="detail in details" ng-if="detail.shortDescription">
            <p>{{detail.name}}</p>
        </li>
    </ul>
</div>

fiddle

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

1 Comment

Thanks for Replying. Actually I wanted only One item from them.

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.