0

I am using ui select in my demo .I am using $scope.$apply() to update the view but it not working.

  • I have few option in my UI multiple select.There is one condition when user select Nicole it blank or remove previous selected value and set only Nicole value in model.
  • here is my plunker

http://plnkr.co/edit/eVXVzlRXJ4KUZaNjID6P?p=preview

Step to reproduce

  • select Amalie from drop down .so model value is 12
  • then select Nicole from drop down .So I remove all previous value from model so now model value only 43 .But it not remove Amelia from view why ? I used $scope.$apply also.

    $scope.OnClickSelect = function(item, $select) {
        if ($scope.restrictNames.indexOf(item.name) != -1) {
            $scope.multipleDemo = [];
            $scope.$apply();
            $scope.multipleDemo.push(item.age);
        } else {
            if ($scope.multipleDemo.indexOf(43) != -1) {
                $select.selected = [];
    
            } else {
                $scope.multipleDemo.push(item.age);
            }
        }
    
    }
    
Huangism
  • 16,278
  • 7
  • 48
  • 74
user944513
  • 12,247
  • 49
  • 168
  • 318
  • look at the first part in this section https://github.com/angular-ui/ui-select/wiki/FAQs – Ronnie Sep 29 '16 at 21:46
  • and here http://stackoverflow.com/a/29907853/736967 – Ronnie Sep 29 '16 at 21:48
  • $scope.$apply is not running because the digest cycle was already running....Also...the component you are using is for adding tags, why would you use tags to remove them? why not some sort of dropdown? check the js file for the component, maybe is not allowing you to play around with something is not intended for that? – Alexander P. Sep 29 '16 at 22:04
  • please share any fiddle – user944513 Sep 30 '16 at 00:17
  • can you tell us what you want to achieve leaving $apply() aside for a while , and why is there a specific cond for Nicole and Amaile.Is that your requirement? – ngCoder Sep 30 '16 at 06:08
  • @user944513 Did you read the links Ronnie previously posted? That second link seems to fit your situation. – Heretic Monkey Sep 30 '16 at 13:32

0 Answers0