我想在我的SelectBoxIt指令中实现angularJS。下面是我的指令的模板html片段(lookup.template.html):
<select class="selectBoxit" ng-model="ngModel">
<option value="" disabled> {{placeholder}}</option>
<option value='{{a.LookupCode}}' ng-repeat='a in lookups'>{{a.Name}}</option>
</select>孤立范围指令:
.directive('lookup', function(){
return {
restrict: 'E',
scope: {
lookups: "=lookups",
ngModel: "=ngModel"
},
templateUrl: 'templates/lookup.template.html',
link: function (scope, element, attrs) {
scope.placeholder = attrs['placeholder'];
$(".selectBoxit").selectBoxIt().on('open', function()
{
//ScrollBar
$(this).data('selectBoxSelectBoxIt').list.perfectScrollbar();
});
}
}
});查找控制器:
.controller('LookupController', function($scope){
$scope.schoolTypeCode = 'GNR';
$scope.schoolTypes = [{ Name: "Kinder Garten", LookupCode: "KG" },
{ Name: "Elemetary", LookupCode: "ELM" },
{ Name: "High School", LookupCode: "HSC" },
{ Name: "Preparatory", LookupCode: "PRP" },
{ Name: "General", LookupCode: "GNR" },
{ Name: "Distance", LookupCode: "DST" }];
});最后,使用指令查看:
<lookup id="cboSchoolType" lookups="schoolTypes"
ng-model="SchoolTypeCode" placeholder="Select School Type"></lookup>SelectBoxIt初始化工作正常,但我注意到了两个问题。首先,未分配默认值(NgModel),其次,在角重复填充options.This之前正在进行初始化,当单击该列表时,将产生一个空的选择列表和以下错误消息:
未定义的TypeError:无法读取未定义的属性“列表”
那么,在选项被角重复填充之后,还有其他方法来设置默认值并触发SelectBoxIt初始化吗?
谢谢。
发布于 2015-05-24 06:38:16
尝试“下拉”而不是“列表”。
因此,不是
$(this).data('selectBoxSelectBoxIt').list.perfectScrollbar();在事件函数中尝试这一行
$(this).data('selectBoxSelectBoxIt').dropdown.perfectScrollbar();https://stackoverflow.com/questions/30312301
复制相似问题