0

I have a Simple Multiselect checkbox dropdown. As I have given below.

<select name="edit_tags" class="form-control" id="advisor_article_tagsx" multiple="" required>
      <option ng-repeat="service in services" value="{{service.id}}">{{service.name}}</option>
</select>

Now I want that some checkbox like index 1,3,5 comes with selected checkbox.

My AngularJS Code is given below.

$scope.article_edit = function(articles) {
  $scope.services = [$scope.model[0], $scope.model[1]];
} 

Then What I need to do for that ??

Thanks

5
  • Do you have any exceptions in developers console? Commented Aug 9, 2017 at 17:46
  • In Console, I did not find any error or exception. Commented Aug 9, 2017 at 17:57
  • Is $http call in the same controller as advisor_article_edit method? Commented Aug 9, 2017 at 18:00
  • Yes, In the same controller. Commented Aug 9, 2017 at 18:05
  • Can you please set up a working fiddle to illustrate the problem you are facing? Since it is hard to say what is actually wrong with your code seeing this short examples. Try initiate $scope.selected = [] before using it in $scope.advisor_article_edit method. Commented Aug 9, 2017 at 18:28

1 Answer 1

1

Why not use ng-options which has good support & also ng-model on select field. So your template can be:

<select name="edit_tags" class="form-control" id="advisor_article_tagsx" multiple="" 
 required ng-model="selected" ng-options="service as service.name for service in services">
</select>

Working plunker example

Sign up to request clarification or add additional context in comments.

3 Comments

You want to show checkbox inside select? That's not default behavior of select field. You need some library for that like this dotansimha.github.io/angularjs-dropdown-multiselect/docs/#/main Check this example: embed.plnkr.co/xWvfWYjaW7TThKZONkv5
Hello Shantanu, I have updated my question. If you don't mind then can you please help me little more. I will be really thankful to you.
@JohnBrad plnkr.co/edit/c90dKXgLOHJn00aN9f3u?p=preview and also check this if you ant to run it just inside that function only: plnkr.co/edit/YhRcshKy0qUfR1wVufY6?p=preview

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.