How to set a value in select that is mounted with ng-options

Asked

Viewed 575 times

0

My HTML is like this:

<select ng-model="cliente" ng-options="t.value as t.displayName for t in clientes"></select>

In the Controller of my JS I have:

$scope.clientes // objeto onde tem todos os clientes para alimentar o select
$scope.cliente // esse é o meu ng-model

My select is working perfectly, I can get the data and save it. My question is the following, how do I fill this select via javascript? I thought when I put up a value on $scope.cliente it would work but it didn’t work!

Does anyone know how to do that? Thank you

1 answer

1

I kept testing here and found the solution.

In my $Scope.client I was setting a type value number and it has to be like string.

Ex: I switched it on:

$scope.cliente = 1;

That’s why:

$scope.cliente = '1';

And it worked!

Hugs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.