Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

168
Visualizações
How can i remove empty/null items from angularjs select dropdown?

'use strict';

var app = angular.module('myApp', []);
app.controller('AppCtrl', function($scope){
    $scope.mail_notifications = [
        {
            "key": "all",
            "value": "For any event on all my projects"
        },
        {
            "key": "selected",
            "value": "For any event on the selected projects only..."
        },
        {
            "key": "only_my_events",
            "value": ""
        },
        {
            "key": "only_assigned",
            "value": "Only for things I am assigned to"
        },
        {
            "key": "only_owner",
            "value": ""
        },
        {
            "key": "none",
            "value": "No events"
        }
    ];
    $scope.mail_notification = 'all';
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.min.js"></script>
<div ng-app="myApp">
<div ng-controller="AppCtrl">        
<select ng-model="mail_notification" ng-options="c.key as c.value for c in mail_notifications"></select>
</div>
</div>

I have a below Fiddle link for reference.

https://jsfiddle.net/maayuresh/mjugfLr0/1/

In above Fiddle , I have json object named mail_notifications. In this some properties are empty , null like this -> ""

This null values are getting displayed in select dropdown list.

My aim is to remove that from the select dropdown. How can i achive that ?

almost 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

FYI,

This null values are getting displayed in select dropdown list.

null is not equivalent to "" (empty string)

To filter the item with value is not an empty string:

$scope.mail_notifications = $scope.mail_notifications.filter(x => x["value"] != "");

You may also work with filtering the item with value is a truthy value as below:

$scope.mail_notifications = $scope.mail_notifications.filter(x => x["value"]);

Demo @ JS Fiddle

almost 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda