1

Community good day, I have a simple query, I have a combo box with material-select, it works perfectly, but when I want to click on the clean button, I need the combo to select me the first value that is disabled.

<div class="input-field col s12">
  <select class="" id="images" ng-model="image" material-select watch>
    <option value="" disabled selected>{{translation.fleet6}}</option>
    <option ng-repeat="item in fleetImage.data" value="{{item.name}}" data-icon="img/fleets/{{item.name}}" class="left circle">{{item.name}}</option>
  </select>
</div>

I thank you in advance

1
  • Thanks for your feedback. And also thanks that you marked the other answer as right. Its a must on Stackoverflow. you are welcome! Commented May 16, 2017 at 9:30

2 Answers 2

1

Here you are. Try it like in this demo fiddle by using a simple "cleanUp" function. While the value of your disabled option is empty you can achieve this by reset your ng-model as an empty string. So your disabled option becomes selected.

View

<div ng-controller="MyCtrl">
  <select class="" id="images" ng-model="image" material-select watch>
    <option value="" disabled selected>{{translation.fleet6}}</option>
    <option ng-repeat="item in fleetImage.data" 
            value="{{item.name}}" 
            data-icon="img/fleets/{{item.name}}" 
            class="left circle">{{item.name}}</option>
  </select>
  <button ng-click="cleanUp()">
    Cleanup
  </button>
</div>

AngularJS application

var myApp = angular.module('myApp', []);

myApp.controller('MyCtrl', function($scope) {

  $scope.image = '';
  $scope.translation = {
    fleet6: 'some value disabled'
  }
  $scope.fleetImage = {
    data: [{
      name: '1'
    },{
      name: '2'
    },{
      name: '3'
    },{
      name: '4'
    },{
      name: '5'
    }
  ]}

  $scope.cleanUp = function () {
    $scope.image = '';
  }
});
Sign up to request clarification or add additional context in comments.

Comments

0

This should work <button ng-click="image=''">click</button>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.