Angular ng-seleccionado por valor
Frecuentes
Visto 355 equipos
0
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-model="serie.meter"
ng-options="(m.SelectBoxName) for m in serie.meterList"
ng-selected="m.Id== serie.Id && m.readingType == serie.readingType"
ng-change="serie.changeMeter()">
</select>
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?
2 Respuestas
0
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;
}
});
contestado el 22 de mayo de 14 a las 14:05
0
Better way to compare m and serie in the controller. and set
$scope.serie.meter
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 javascript angularjs reference or haz tu propia pregunta.
Can you show what serie.meterList looks like? - Jerrad