I am using Jquery Selectric on my page to render a select box in my angularJS app, so I decided to create a directive to render the element, below is the directive and how I use it.
The Directive:
angular.module('shoeRevamp.directives')
.directive('selectric', function () {
return {
restrict: 'A',
scope: {countries: '='},
controller: function ($scope, $element, $attrs) {
console.log($scope.countries);
},
link: function (scope, el, attrs) {
if( $("select").length) {
$(el).selectric();
}
}
};
});
How I use it (Jade/Pug):
select(selectric ng-model='country' countries='countries' ng-options='country.name for country in countries track by country.symbol')
The Problem
When I load the page and try to open the select box it complains with the error below without displaying any of the countries:
Error Message
jquery.selectric.min.js:1 Uncaught TypeError: Cannot read property 'offsetTop' of undefined
Another Problem
When I add priority: -1000,
It displays the countries, but it looses its Selectric styles and behaviour.
I need help.