2017-04-21 168 views
0

我有一個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; 
} 

如何訪問年開業屬性?

回答

0

如果您所要做的只是防止提交行爲,只需將'type =「按鈕」'添加到您的按鈕元素即可。

<button type="button" class="btn btn-default" ng-click="vm.openDateHandler($event)"> 

默認情況下,表單中的按鈕將用作提交按鈕,除非它被賦予不同的類型。

您不應該混淆日期選擇器的打開狀態以防止表單提交。