podio / jquery-mentions-input

MIT License
985 stars 333 forks source link

Issue with integration. Getting data for the plug-in #180

Closed devisha1 closed 3 years ago

devisha1 commented 6 years ago

I wrote a directive for the Plug-in to integrate it to my source-code. Here is the sample of the directive:

directive('mention', function (DataModel) { return { restrict: 'A', scope: true, controller: function ($scope, $element, $attrs) { console.log("Hola i am here") $scope.onSlide = function (e, ui) { $scope.model = ui.value; // or set it on the model // DataModel.model = ui.value; // add to angular digest cycle $scope.$digest(); }; }, link: function (scope, el, attrs) {

        var options = {
            slide: scope.onSlide
        };

        // set up slider on load
        angular.element(document).ready(function () {
            scope.$slider = $(el).mentionsInput({
                onDataRequest:function (mode, query, callback) {
                    var data = [
                      { id:1, name:'Kenneth Auchenberg', 'avatar':'http://cdn0.4dots.com/i/customavatars/avatar7112_1.gif', 'type':'contact' },
                      { id:2, name:'Jon Froda', 'avatar':'http://cdn0.4dots.com/i/customavatars/avatar7112_1.gif', 'type':'contact' },
                      { id:3, name:'Anders Pollas', 'avatar':'http://cdn0.4dots.com/i/customavatars/avatar7112_1.gif', 'type':'contact' },
                      { id:4, name:'Kasper Hulthin', 'avatar':'http://cdn0.4dots.com/i/customavatars/avatar7112_1.gif', 'type':'contact' },
                      { id:5, name:'Andreas Haugstrup', 'avatar':'http://cdn0.4dots.com/i/customavatars/avatar7112_1.gif', 'type':'contact' },
                      { id:6, name:'Pete Lacey', 'avatar':'http://cdn0.4dots.com/i/customavatars/avatar7112_1.gif', 'type':'contact' }
                    ];

                    data = _.filter(data, function(item) { return item.name.toLowerCase().indexOf(query.toLowerCase()) > -1 });

                    callback.call(this, data);
                }
            });
        });
    }
}

});

I cannot get the user data for @mentions. Can you advise so as to what the issue might have been. I feel that AngularJS is getting the data first. Please advise.