2016-12-10 22 views
1

我特林使用的材料组分中的角2镖为数字输入材料输入类型号:是否有角2镖

<material-input type="number"></material-input> 

,但它的行为就像一个正常输入。在文档中它支持类型“数字”。我做错了什么?或者不是数字类型实现了吗?

谢谢你的任何建议。

+0

这真的很烂他们没有这方面的解决方案: - /发现迄今为止工作的任何东西? – Blackbam

回答

0

我认为你需要设置一个errorMsg

<material-input type="number" errorMsg="That's not a number"></material-input> 

此行https://github.com/dart-lang/angular2_components/blob/a0eff879a6cb347b8beb95ed758c02c6dd9dfaa0/lib/src/components/material_input/material_input.dart#L232似乎表明type="tel"type="number"设置为text的内部输入元素,而这条线https://github.com/dart-lang/angular2_components/blob/a0eff879a6cb347b8beb95ed758c02c6dd9dfaa0/lib/src/components/material_input/material_input.dart#L61errorMsg时使用和type="number"时输入无效号码。

+0

您的解决方案不起作用。 我试图从库中复制适当的文件,编辑过的导入和关键行 - 然后是错误消息,而不是能够写信的作品。 我没有实现的是小箭头键,就像在standart html5 或者像angularjs [这里](https://material.angularjs.org/latest/demo/input) (第二块,“美元小时汇率) – user2522115

+0

对不起,不知道。 –

2

我可以分享我的个人实验,尝试有一个数字(整数)输入。它在所有浏览器上都无法正常工作,但我想要在Android和iOS上显示正确的键盘。我所做的是以编程方式强制内部输入元素的类型。看起来在Firefox上它不会阻止输入文本,但会显示一条消息(“请输入一个数字”)。它不处理小数既(即它期待一个整数)

initInputNumber(MaterialInputComponent inputComponent) { 
    inputComponent.type = "number"; 
    InputElement inputElement = inputComponent.inputEl.nativeElement; 
    inputElement.type = "number"; 

    // http://stackoverflow.com/questions/6178556/phone-numeric-keyboard-for-text-input 
    // As of mid-2015, I believe this is the best solution: 
    // <input type="number" pattern="[0-9]*" inputmode="numeric"> 
    inputElement.attributes["inputmode"] = "numeric"; 
    inputElement.pattern = "[0-9]*"; // this and only this works 0-9 
    } 

我不知道这是最好的解决办法,但我觉得很难有一个完整的跨浏览器解决方案