2016-12-15 27 views
1

我正在嘗試爲iOS上的Angular 2應用程序啓動一個數字鍵盤,但無法獲得我想要實現的功能。這裏是我的代碼請告訴我我需要做什麼變化Angular 2數字鍵盤啓動

<input type="number" minlength="0" inputmode="numeric" pattern="[0-9]*" placeholder="Month" formControlName="month" maxlength="2"> 

我也嘗試改變輸入類型=「電話」,但沒有運氣。 我不斷收到enter image description here當我試圖實現enter image description here

這裏的文章中,我所遇到的要達到什麼,我試圖用,但沒有運氣 http://danielfriesen.name/blog/2013/09/19/input-type-number-and-ios-numeric-keypad/

回答

4

使用type = 「文本」 與模式

的iOS開發者文檔實際上包括如何觸發不同的鍵盤一個section並且他們推薦使用type="text"以及特定模式"[0-9]*" or "\d*"來觸發數字鍵盤d,就像這樣:

<input type="text" pattern="[0-9]*"> 

不幸的是,當你開始在iOS設備上的字段中輸入,它實際上帶來了只有擁有數字小鍵盤,而不是鍵盤其中也包括像時期的符號,必要小數。在Android上,您只需使用普通鍵盤。

enter image description hereenter image description here

+0

嘗試過沒有運氣 – Vijay

+0

請閱讀Apple官方文檔https://developer.apple.com/library/content/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html。數字鍵盤與角度無關。感謝 –

+0

,所以當我將iPad置於縱向模式但不處於橫向模式時,更改工作。但謝謝:) – Vijay

0

你的代碼完全,因爲它是工作對於我在iOS 10.2 OSX模擬器上的Safari。這裏是我的plunker

My Plunker

import { Component } from '@angular/core'; 

@Component({ 
    selector: 'my-app', 
    template: `<h1>Hello {{name}} <input type="number" minlength="0" inputmode="numeric" pattern="[0-9]*" placeholder="Month" formControlName="month" maxlength="2"> 
</h1>` 
}) 
export class AppComponent { name = 'Angular'; } 

見下enter image description here

+0

但是當我真正在iPad上用科爾多瓦部署的應用它不工作。也許我應該檢查Cordova的文檔。 – Vijay