1

I have an array of values with possible null. AngularJS displays those by default as a value, but I want to skip those values entirely.

Is my only option to create a filter or is there any other solution out there?

My code:

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

app.controller('FooController', function($scope) {
    $scope.foo = [null, 'foo', 'bar'];
});

<body ng-app="fooapp">
    <div ng-controller="FooController">
        <select ng-model="foomodel" ng-options="f for f in foo"></select>
    </div>
</body>

Here's a plunker:

http://plnkr.co/edit/ZGbkbtQ2xNQuoaowUK5z?p=preview

2 Answers 2

3

You can do it by using a filter:

<select ng-model="foomodel" ng-options="f for f in foo | filter: '!null'"></select>
Sign up to request clarification or add additional context in comments.

1 Comment

In my opinion this is a ugly hack. I opened a issue for this in AngularJS project on GitHub.
0

Try this:

<select ng-model="foomodel" ng-options="f for f in foo | filter:'!'+null"></select>

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.