Im trying to set an option with angular bootstrap select(in my example I use a simple button), I update the ng-model and I can see the select changes, and quickly return to the default value.
This is a snippet of code:
function SelectCtrl($scope, $timeout) {
$scope.options = [
{value: 'option1', text: 'option 1'},
{value: 'option2', text: 'option 2'},
{value: 'option3', text: 'option 3'}
];
$scope.updateOption = function() {
$scope.theOption = $scope.options[0];
$timeout(function() {
$('.selectpicker').selectpicker('refresh');
});
}
}
This is the EXAMPLE .
Bug in the directive defined in angular-bootstrap-select.js, remove this part and try:
ngModel.$render = function () {
$timeout(function () {
element.selectpicker('val', element.val() || '');
});
};
Commenting out the line "$scope.theOption = $scope.options[0];" should work.
This should work:
angular.module('selectDemoApp', ['angular-bootstrap-select', 'angular-bootstrap-select.extra']);
function SelectCtrl($scope, $timeout) {
$scope.options = [
{value: 'option1', text: 'option 1'},
{value: 'option2', text: 'option 2'},
{value: 'option3', text: 'option 3'}
];
$scope.updateOption = function() {
//$scope.theOption = $scope.options[0];
$timeout(function() {
$('.selectpicker').selectpicker('refresh');
});
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.