0

I have a pop-up with multi-select drop down.

Multi-Select Dropdown Code

<select name="edit_tags" class="form-control" id="advisor_article_tagsx" multiple="" 
   required ng-model="article_selected" ng-options="article_service as article_service.name for article_service in article_services">
</select>

There is an array article_services which is used in multi-select, I am fetching this array from below code.

$http.get(url + 'service_provided').
     then(function (response) {
         $scope.article_services = response.data.service_provided;
         //$scope.article_selected = [$scope.article_services[0], $scope.article_services[1]];
});

Now I want that when I click on Edit Button with ng-click="advisor_article_edit()" to open pop-up, my multi-select checkbox comes with some selection. I want that Select must be work in below function but unfortunately it doesn't work.

$scope.advisor_article_edit = function () {
        // I need selection work from here. But it doesn't.
        $scope.article_selected = [$scope.article_services[3]];
 }

2 Answers 2

1

It should work, like in the snippet.:-

var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
  
  $scope.cars = [{id:1, name: 'Audi'}, {id:2, name: 'BMW'}, {id:1, name: 'Honda'}];
  $scope.advisor_article_edit = function () {       
        $scope.article_selected = [$scope.cars[1]];
  }
});
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="myCtrl">
  
<select name="edit_tags" class="form-control" id="advisor_article_tagsx" multiple="" 
   required ng-model="article_selected" ng-options="car as car.name for car in cars">
</select>

<button ng-click="advisor_article_edit()">Edit</button><br>
Selected : {{article_selected}}
</div>

Working Plunkar Link

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

1 Comment

1

I believe you need to trigger the click:

var cb = angular.element('some-selector');
cb.triggerHandler('click');

This should be done in a directive as it's dom manipulation

2 Comments

If you don't mind then can you give complete solution here ??
I can't as I'm at work but if you create a jsFiddle or CodePen or something with your issue I can try to fix it

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.