AngularJS, Select and binding to value -


I have a scenario that I thought was logical, but it seems that angular does not support it.

So, I have such a scope / controller, which is an array of objects, such as a list of user types:

  $ scope.userTypes = [{text: "Buyer ", Value:" 1 "}, {text:" seller ", value:" 2 "}, {text:" buyer / seller ", value:" 9 "}]; $ Scope.user = New User (Global SelectedUsert);  

Where a user is defined like this:

  function user (userType) {this.userType = userType; This.isAdminUser = false; This.isActive = True; This.roleDisabled = true; };  

And I want to put a selected element with the list of options for typing values ​​of "value" property and user type for the text of the "text" property and select array object The Value for property of "value" allows the user to set the value with the code.

So when I create this user using this code

  $ scope.user = new user ("9");  

Select this should initialize selection with "buyer / seller".

Reading the documents of the selected element in angular and ng-options, it seems that it is impossible to do. I tried this

  & lt; Select name = "usertypedata" id = "UsersTypeData" ng-model = "user.userType" ng-disabled = "user.roleDisabled" ng-option = "UserType for UserType in UserType. Track with. & Gt; & lt; / select & gt;  

And when we choose the option, I want the ng-model

I have two answers, the first answer is that what PSL did in its comments earlier The second answer is

Instead of binding ng-options to an array, I keep it in an object and have worked

to expand it further. It may be that I am not using angular to populate / and control the behavior of the html page / form, completely angular solution from start to finish.

But Afterwards, I am submitting a normal html / form which for All the data will be submitted inside the M.M. and the normal form / submit will use the selection / option value to submit that value, and not the NG-model

but the NG-model is important option for me program Was important for choosing.


Comments