HTML:
<select style='width:60px;' combobox>
<option ng-repeat='item in sizePriceWeighArr' value='{{ item.id }}' price='{{ item.price }}' weight='{{ item.weight }}' size='{{ item.size }}'>{{ item.size }}</option>
</select>
JS:
.controller('productController', ['$scope', '$location', '$http', '$q', '$window', '$stateParams', function($scope, $location, $http, $q, $window, $stateParams) {
// Some code here to form array of products
$scope.sizePriceWeighArr = productObj.sizePriceWeigh;
}])
.directive('combobox', function() {
return {
restrict: 'A',
link: function($scope, element, attrs) {
$(element).combobox();
}
}
})
В директиве я формирую список jQuery-UI combobox. Но мне нужно как-то уловить событие изменения при выборе, на контроллере или в директиве.
Вы в настоящее время используете select, поэтому почему бы просто не использовать ngChange:
<select style='width:60px;' combobox ng-change="changeFunction()">
<option ng-repeat='item in sizePriceWeighArr' value='{{ item.id }}'
price='{{ item.price }}' weight='{{ item.weight }}' size='{{ item.size }}'>
{{ item.size }}</option>
</select>
ЯШ:
.controller('productController', ['$scope', '$location', '$http', '$q', '$window', '$stateParams', function($scope, $location, $http, $q, $window, $stateParams) {
// Some code here to form array of products
$scope.sizePriceWeighArr = productObj.sizePriceWeigh;
function changeFunction(){
//your code.
}
}])
.directive('combobox', function() {
return {
restrict: 'A',
link: function($scope, element, attrs) {
$(element).combobox();
}
}
})