5

I use angularJs and bootstrap. I have made an accordion where I have put a select for choose the value of the filter and the data-ng-model which doesn't work (the select works if he is not in an accordion). Here is my code:

<accordion close-others="oneAtATime">
    <accordion-group is-open="isOpen">
        <accordion-heading>
            Country<i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-down': isOpen, 'glyphicon-chevron-right': !isOpen}"></i>
        </accordion-heading>
        <select data-ng-model="country" class="input-medium inputFilter form-control">
            <option value="">All country</option>
            <option value="1">Switzerland</option>
            <option value="2">France</option>
            <option value="3">Spain</option>
        </select>
    </accordion-group>
</accordion>
<div data-ng-repeat="city in listcity |filter:country">
    {{city.name}}, {{city.country}}
</div>

I have look at UI-Bootstrap for the accordion. I thinks I had to do a directive for make it work but the directive doesn't work with the accordion. here is my directive which doesn't work

app.directive('accordion', function () {
return {
    scope: {
        dataNgModel: '=',
    },
  };
});

1 Answer 1

6

I am not sure if this is what you wanted. But i use ng-change to setup the new filter value.

Controller:

function AccordionDemoCtrl($scope) {
  $scope.oneAtATime = true;
  //default: all countrys
  $scope.country = '';
  //example data
  $scope.listcity = [{
    name: 'Madrid',
    country: '3'
  }, {
    name: 'Paris',
    country: '2'
  }, {
    name: 'Lyon',
    country: '2'
  }, {
    name: 'Zurich',
    country: '1'
  }];

  //set a new selection
  $scope.setCountry = function(cid) {
    $scope.country = cid;
  }
}

Markup:

 <select ng-model="country" ng-change="setCountry(country)" class="input-medium inputFilter form-control">

See it working here

Btw: The example directive is the shortest I have ever seen. Ahh, I whish it was that easy:-)

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

2 Comments

Thanks it's exactly what i was looking for. It was the first time I was trying to do a directive :), I stil have a lot of work to do haha
Hello guys, am stuck with an angularjs-accordion problem can you help ? ... Its HERE

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.