我在我的页面上使用Jquery Selectric来呈现我的angularJS应用程序中的选择框,因此我决定创建一个指令来渲染元素,下面是指令以及我如何使用它。AngularJS jquery指令
的指令:
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();
}
}
};
});
我如何使用它(玉/帕格):
select(selectric ng-model='country' countries='countries' ng-options='country.name for country in countries track by country.symbol')
的问题
当我加载页面并重打开选择框它抱怨错误下面没有显示铺设任何国家:
错误消息
jquery.selectric.min.js:1 Uncaught TypeError: Cannot read property 'offsetTop' of undefined
另一个问题
当我添加priority: -1000,
它显示了国家,但它失去其Selectric风格和行为。
我需要帮助。
这是你的'我怎么使用它'部分的玉/帕格? –
@HopefulLlama是的,多谢指出 –
尝试将链接函数包装到$ timeout ddeclaration中。 –