typescript 如何禁用离子输入?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39868222/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make ion-input disabled?
提问by Sveta Antrapovich
How can I disable ion-input
?
我怎样才能禁用ion-input
?
<ion-input type="text"></ion-input>
I'm new at Ionic Framework, it is rather similar to HTML, but there is no property for attribute to disable it like:
我是 Ionic Framework 的新手,它与 HTML 非常相似,但没有属性可以禁用它,例如:
.prop("disabled", true)
.prop("disabled", true)
回答by Julianesten
Ionic 2:
离子2:
Static property:
<ion-input disabled="true" type="text"></ion-input>
Dynamically:
<ion-input disabled="{{isDisabled}}" type="text"></ion-input>
After in the component(.ts file):
private isDisabled: boolean=false;
静态属性:
<ion-input disabled="true" type="text"></ion-input>
动态:
<ion-input disabled="{{isDisabled}}" type="text"></ion-input>
在组件(.ts 文件)之后:
private isDisabled: boolean=false;
回答by Mihir Patel
disabled in small characters, it works on the boolean mechanism. bind the object of true and false so you will get the result.
在小字符中禁用,它适用于布尔机制。绑定 true 和 false 的对象,这样你就会得到结果。
<ion-input disabled="{{inputDisabled}}" [(ngModel)]="drill_plus" placeholder="Drill Plus" type="number"></ion-input>
your ts export class
你的 ts 导出类
inputDisabled: boolean = false;
condition
状况
this.inputDisabled = true;
works for me. try this, hope you will get the answer.
对我来说有效。试试这个,希望你能得到答案。
回答by ImFarhad
if you want to disable the input field without any condition you can use disabled directivelike this:
如果您想在没有任何条件的情况下禁用输入字段,您可以使用如下禁用指令:
<ion-input type="text" placeholder="Enter Input" disabled></ion-input>
if you want to disable the input field on some condition, you can define a variable in your typescript file and assign it to disabled directivelike this:
如果您想在某些条件下禁用输入字段,您可以在打字稿文件中定义一个变量并将其分配给禁用指令,如下所示:
example.ts:
private isDisabled: boolean = false;
example.ts:
私有 isDisabled: boolean = false;
example.html
示例.html
<ion-input type="text" placeholder="Enter Input" [disabled]="isDisabled"></ion-input>
so if isDisabledvariable's value is true,it will be disabled, otherwise it will enable and user can input whatever he/she wants.
所以如果isDisabled变量的值为真,它将被禁用,否则它将启用并且用户可以输入他/她想要的任何内容。
Hope it will help some one in future.
Thanks
希望它会在未来帮助某人。
谢谢