ng单击两次触发单选按钮

时间:2019-08-22 16:05:03

标签: angularjs

我有以下内容:

<div class="csv-radio-group">
    <input type="radio" id="csv" name="export-type" ng-value="csv" ng-click="$ctrl.setExportType($event, 'csv')">
    <label for="csv">csv</label>
</div>
<div class="qfx-radio-group">
    <input type="radio" id="qfx" name="export-type" ng-value="qfx" ng-click="$ctrl.setExportType($event, 'qfx')">
    <label for="qfx">qfx</label>
</div>
<div class="ofx-radio-group">
    <input type="radio" id="ofx" name="export-type" ng-value="ofx" ng-click="$ctrl.setExportType($event, 'ofx')">
    <label for="ofx">ofx</label>
</div>

在我的控制器中包含以下内容:

const setExportType = (event, type) => {
    exportTypeSelection = type;
    if(event){
        event.stopPropagation();
    }
    console.log(exportTypeSelection);
    console.log(event);
}

当我单击csv按钮时,我看到:

csv
MouseEvent {isTrusted: true, isDefaultPrevented: ƒ, 
stopImmediatePropagation: ƒ, isImmediatePropagationStopped: ƒ, 
screenX: 1628, …}
undefined
undefined

为什么单选按钮两次触发,我该如何解决?我知道我可以使用ng-model,但是如果我要使用ng-click怎么办?谢谢!

0 个答案:

没有答案