我在我的頁面上使用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中。 –