gleber1
@gleber1

Как реализовать директиву списк чекеров-кнопок в angular без ng-click?

Некрасивый вариант , зато свой
(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>
  • Вопрос задан
  • 148 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы