2016-12-10 25 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 
    } 

我不知道這是最好的解決辦法,但我覺得很難有一個完整的跨瀏覽器解決方案