angularjs - select box : display text 'error' if value not exist in array -


I have added an important value that is defined below, which can be used for selection using the ng-option

I'm using this key value pair to display the selection box in the ng-option

  & lt; Ng-model = "selected bucket" ng- options = "multiple =" multiple "& gt; for row in row.value rows.display as bucketEnum & Lt; / Select & gt;  

Now if I set the NG-model i.e .. $ scope.selectedBucket = 10 , I want to display the text error $ scope.BucketEnum is not in the array value for all values ​​ error What is possible to show.

Note

SCENARIO

I'm looking at this in a more common way , A filter to do this

SCENARIO

Historical data in the database, which has some garbage and some good data

each For the garbage value, I have to show the valid value to choose along with the current garbage value, so the end users have to fix it.

Will this satisfy your needs?

  app.filter ('bootstrap value', function () {Return function (initial, basebucket) {var for results = []; (var i = 0; i & lt; initial.length; i ++) for {var flag = false; (var j = 1; j & lt; basebucket.length; J ++) {// 1 or 0. If you Call (initial [i] === basebket [j] value) {flag = true; result push (basebacket [j]); break; // if there are duplicated elements}} if (! Flag) result Push (baseback [0])} return result;};});  

Use it to start the selected bucket in your controller:

  // settings initials $ scope.selectedBucket = $ filter ('bootstrapValues' ) (InitialSet, $ Scope.bucketEnum);  

Does this help?

EDIT: There have been some changes here, if the price is not in the bucket, then it adds the element to the list with the error list and as a selected value.


Comments