Chosen Angular directive doesn't get updated

前端 未结 2 2077
既然无缘
既然无缘 2021-01-02 12:21

I\'ve followed this great tutorial (link) for Chosen and Angular (code is pretty much same)

Here is my directive:

app.angularModule.directive(\'chose         


        
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-02 13:18

    I've solved it, the solution is pretty easy and straightforward actually (when you get how Angular directives work). Here is whole code for directive:

    app.angularModule.directive('chosen', function() {
        var linker = function (scope, element, attrs) {
            var list = attrs['chosen'];
    
            scope.$watch(list, function () {
                element.trigger('chosen:updated');
            });
    
            scope.$watch(attrs['ngModel'], function() {
                element.trigger('chosen:updated');
            });
    
            element.chosen({ width: '350px'});
        };
    
        return {
            restrict: 'A',
            link: linker
        };
    });
    

提交回复
热议问题