如何在一个按钮中有一个ng-if双向条件

How can have an ng-if two way conditionality within a button?

本文关键字:有一个 ng-if 条件 按钮 一个      更新时间:2023-09-26

我有一个按钮,如果浏览器是Internet explorer,我想不自动对焦于文本字段。button元素中还有其他id和其他东西我没有包括。我知道我可以包含两个独立的ng-if语句,并从外部重复这两个按钮类,一个带强制焦点,一个不带强制焦点。

有没有一种可能的方法把ng-if在按钮标签,所以我不需要在按钮标签重复其他的东西?

非IE

<button type="button"
    otherStuff
    ng-click="doStuff(); forceFocus('currentPassword')"  
</button>
IE

<button type="button"
    otherStuff
    ng-click="doStuff()"  
</button>

在你的forceFocus函数中添加一个参数:isInternetExp。如果isInternetExp值为真,你可以返回false

forceFocus('currentPassword', isInternetExp)