HTML 檔案
<input type="number" min="10" max="100" (keydown)="checkLength1($event,inputNumber)"#inputNumber/>
ts檔案
checkLength1(e: { key: string | number; keyCode: number; preventDefault: () => void; }, input: { value: string; }) {
const keyValue = e.key; const numberOnlyPattern = '[0-9] ';
const newValue = input.value (isNaN(keyValue) ? '' : keyValue.toString());
const match = newValue.match(numberOnlyPattern);
if ( newValue > 12 || !match || newValue === '') {e.preventDefault();} }
規格檔案
it("checkLength1", () => { const e ={ key: "1", keyCode: 1, preventDefault : () => void }
const input = {value:"1" }
component.onKeyPressHours(e, input); });
我正在嘗試為“checkLength1”方法撰寫測驗用例。但是在為引數“e”構造物件時出現錯誤。請幫我解決這個問題
uj5u.com熱心網友回復:
只需替換void為null.
it("checkLength1", () => {
const e = { key: "1", keyCode: 1, preventDefault : () => null };
...
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/462672.html
