透過 onblur 判斷是否有選取既有選項,若未選取則動態設定 ng-model
.directive('selectonblur', function () {
return {
require: 'uiSelect',
link: function ($scope, $element, attrs, $select) {
var searchInput = $element.querySelectorAll('input.ui-select-search');
if (searchInput.length !== 1) throw Error("bla");
searchInput.on('blur', function () {
if (!$select.ngModel.$viewValue)
$scope.$apply(function () {
var user = { name: $select.search };
$select.ngModel.$setViewValue(user);
});
});
}
}
})
沒有留言:
張貼留言