Angular ng-seleccionado por valor

I am using AngularJS with an select element. I'm using ng-model, ng-options and ng-selected. My only problem is that ng-selected calls it by reference and not by value.

<select class="faiconselect"
        ng-options="(m.SelectBoxName) for m in serie.meterList"
        ng-selected="m.Id== serie.Id && m.readingType == serie.readingType"

I simply want to compare if a value of m equals a value of serie.

Is there a way to make ng-selected use call by value, and not call by reference?

preguntado el 22 de mayo de 14 a las 13:05

Can you show what serie.meterList looks like? -

2 Respuestas

ng-selected does not apply to a select element, it applies to an option element. I'm not entirely sure what you're trying to do, but you probably want to determine which element you want to be selected in your controller and then assign serie.meter there.

Por ejemplo:

angular.forEach($scope.serie.meterList, function(value, key){        
    if(value.Id == $scope.serie.Id && value.readingType == $scope.serie.readingType)
        $scope.serie.meter = value;

Ejemplo de JSBin

contestado el 22 de mayo de 14 a las 14:05

Better way to compare m and serie in the controller. and set


with needed value.

contestado el 22 de mayo de 14 a las 13:05

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.