Angular指令打开日期选择器
问题描述:
我有一个Angular指令,其中包含一个带日期选择器的表单。我正在尝试创建一个函数来保持单击按钮从调用窗体上提交。我无法确定在哪里找到.opened属性。当我用ng执行打开时,单击所有工作。以下是示例代码。Angular指令打开日期选择器
HTML:
<form ng-submit="editAlert.$valid && vm.handleSubmit()" name="editAlert" id="editAlert" class="buffer-bottom" novalidate>
<div class="form-group">
<label class="control-label" for="effectiveDate">Effective Date</label>
<div class="input-group">
<input type="text" class="form-control" uib-datepicker-popup="MM-dd-yyyy" is-open="dpEffectiveDate.opened" ng-model="alertMsg.effectiveDateFmt" name="effectiveDate" id="effectiveDate">
<span class="input-group-btn">
<button class="btn btn-default" ng-click="vm.openDateHandler($event)"><i class="fa fa-calendar"></i></button>
</span>
</div>
<p class="help-block" ng-show="editAlert.effectiveDate.$error.endBeforeStart">Effective date must be before expire date.</p>
</div>
</form>
我也试过路过dpEffectiveDate到openDateHandler功能。
下面是我的打字稿功能
openDateHandler = ($event) => {
$event.preventDefault();
//dpDate.opened = !dpDate.opened;
}
如何访问年开业属性?
答
如果您所要做的只是防止提交行为,只需将'type =“按钮”'添加到您的按钮元素即可。
<button type="button" class="btn btn-default" ng-click="vm.openDateHandler($event)">
默认情况下,表单中的按钮将用作提交按钮,除非它被赋予不同的类型。
您不应该混淆日期选择器的打开状态以防止表单提交。