Angular js and bootstrap ui date picker not open in chrome on clicking on icon

烈酒焚心 提交于 2019-12-10 12:15:57

问题


I have date picker in angular using bootstrap UI. This code is working very fine in IE but its not get open in chrome. As after calling the method open () input box get focused but date picker popup not opens. Any help will be really appreciable. Thanks in advance

<p class="input-group">
<input is-open="opened" type="text" datepicker-popup="M/d/yyyy" ng-model="Date" datepicker-options="dateOptions" />
                               <span class="input-group-btn">
                                  <button type="button" class="btn btn-default" ng-click="open()"><i class="glyphicon glyphicon-calendar"></i></button>
                               </span>
                        </p>

Java Script

$scope.open = function () {    
    $scope.opened = true;                                                                                    
};

回答1:


You need to stop the click event from propagating from the button as it will cause the datepicker to close instantly...

<button type="button" class="btn btn-default" ng-click="$event.stopPropagation(); open();">
    <i class="glyphicon glyphicon-calendar"></i>
</button>

Demo - JSFiddle




回答2:


it may correct way to use above solution .
when you use $event.preventDefault(); $event.stopPropagation(); be carefully . it may affect other components events too. the live code is http://jsfiddle.net/mDLzn/34/

$scope.open = function (event) { 
event.stopPropagation();
event.preventDefault();
$scope.opened = true; 
console.log('foo'); };


来源:https://stackoverflow.com/questions/24501725/angular-js-and-bootstrap-ui-date-picker-not-open-in-chrome-on-clicking-on-icon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!