Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working if ng-model is of datatype number #51

Open
DJHightower opened this issue Apr 4, 2015 · 4 comments
Open

Not working if ng-model is of datatype number #51

DJHightower opened this issue Apr 4, 2015 · 4 comments

Comments

@DJHightower
Copy link

Successfully tested your component with model-values of type string.
But if i bind it to a model of type number the component always Shows 'Nothing selected'.
I tried it with static values like in this sample code:

            <ol class="nya-bs-select form-control" ng-model="testmodel">
                <li value="0" class="nya-bs-option">
                    <a>
                        Beratungswunsch durch Kunden
                    </a>
                </li>
                <li value="1" class="nya-bs-option">
                    <a>Beratung durch Beraterinitiative</a>
                </li>
            </ol>

in JavaScript:

this works: $scope["testmodel"] = "1";
this does not work: $scope["testmodel"] = 1;

@DJHightower
Copy link
Author

Then i tried to help myself using dynamic options. I created this array in my viewmodel:

        $scope.GuidanceInitiatorOptions = [
            {
                Id: Model.GuidanceInitiator.Customer,
                DisplayName: "Beratungswunsch durch Kunden"
            },
            {
                Id: Model.GuidanceInitiator.Analyst,
                DisplayName: "Beratung durch Beraterinitiative"
            },
        ];

and modified my html to:

            <ol class="nya-bs-select form-control" ng-model="testmodel">
                <li class="nya-bs-option" nya-bs-option="option in GuidanceInitiatorOptions track by option.Id">
                    <a>{{option.DisplayName}}</a>
                </li>
            </ol>

But this always writes the full option-object into my ng-model "testmodel".But i only want to store the numeric value "Id"! I tried to change the select-statement to "option.Id as option in GuidanceInitiatorOptions". But that gives exceptions in your code.
Whats the correct way to bind to the Id in this case? Looks like there is no example for this in your collection.

@lordfriend
Copy link
Owner

You need to use value expression in each option, see the example of Value Expression
In your second example, you can add a attribute value="option.Id" to nya-b-option directive

<ol class="nya-bs-select form-control" ng-model="testmodel">
      <li class="nya-bs-option" value="option.Id" nya-bs-option="option in GuidanceInitiatorOptions track by option.Id">
           <a>{{option.DisplayName}}</a>
      </li>
</ol>

@kumarabrol
Copy link

Can we add ng-change to nya-bs-select dropdown??
If yes,please share some example

@lordfriend
Copy link
Owner

ng-change relies on the native form controls, this directive is not a native form control

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants