A
A
Abc Edc2015-06-22 13:51:41
JavaScript
Abc Edc, 2015-06-22 13:51:41

How to implement checker-button list directive in angular without ng-click?

Ugly option, but

(function () {
    'use strict';
    angular
        .module('app.widgets')
        .directive('ccTags', ccTags);
    function ccTags() {
        var directive = {
            scope: {
                label: "@"
                dictionary: "=dictionaryList",
                arrM: '=arrayModel'
            },
            link: link,
            templateUrl: 'scripts/widgets/templates/ccTags.html'
        };
        return directive;
        function link($scope, element, attrs, controller) {
            var a=[];
            $scope.pushInArr= pushInArr;
            function pushInArr (el){
                if(a.indexOf(el)<0){
                    a.push(el);
                    $scope.filter = a.toString();
                }
                else{
                    a.splice(a.indexOf(el),1);
                    $scope.filter = a.toString();
                }
            }
        }
    }
})();

<label for="btn-group" ng-if="label">{{label}}</label>
<div class="row">
    <div class="btn-group" id="btn-group">
        <label class="btn btn-default"  ng-repeat="c in dictionary" ng-click="pushInArr(c.id)"
               ng-model="arr-m[c.id]" >
            {{(c.name ? c.name : c)}}
        </label>
    </div>
</div>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question