我正在 ionic4 中创建一个应用程序,我有一个功能,用户可以输入唯一的整数 (0-9),所以我想限制任何其他字符,即字母、点等。
我试图限制使用以下指令
@HostListener('input', ['$event']) onInputChange(event) {
this.inputElement = this._el.nativeElement.getElementsByTagName('input')[0];
const initalValue = this.inputElement.value;
this.inputElement.value = initalValue.replace(/[^0-9]*/g, '');
if (initalValue !== this.inputElement.value) {
event.stopPropagation();
}
}
Run Code Online (Sandbox Code Playgroud)
它正在正确更新 ngModel,但仍然在输入字段中可见无效字符。
我尝试了另一种选择,如下所示
html
<ion-input type="text" placeholder="Enter number"
[(ngModel)]="userCount"
name="userCount"
(ionInput)="countChange($event)">
</ion-input>
Usercount: {{userCount}}
Run Code Online (Sandbox Code Playgroud)
打字稿
countChange(event) {
event.target.value = event.target.value.replace(/[^0-9]*/g, '');
}
Run Code Online (Sandbox Code Playgroud)
其在 HTML 中的打印值正确无无效字符,但在输入中显示无效字符。
如果我在 input 中输入 5+,ngModel 中的值显示 5 但输入字段显示 5+
当我输入 5++ 然后再次输入 5 时,输入字段现在显示 55。
如何限制输入只接受整数值 [0-9]
我正在学习流星并关注此链接.
当我使用Session.set 它时,Session is not defined在控制台中给我错误
我的客户端文件夹中的main.js文件代码如下
PlayersList = new Meteor.Collection('players');
if(Meteor.isClient) {
Template.leaderboard.events({
'click .playerName ': function(){
var playerId = this._id;
Session.set('selectedPlayer', playerId);
}
});
}
Run Code Online (Sandbox Code Playgroud)
我不知道我做错了什么
我已经读过这篇文章了.
我的文件在客户端文件夹内,代码也在isClient条件内.它仍然给我错误.
我HealthKit在我的应用程序中使用读取用户的每日步骤数据,为此我HealthKit在我的应用程序中启用.
我上传的应用,而无需NSHealthShareUsageDescription和NSHealthUpdateUsageDescription关键info.plist.
苹果拒绝了该应用程序,并说这两个关键必须在info.plist.
NSHealthUpdateUsageDescription - 阅读卡路里计数数据的每日步骤数据
NSHealthShareUsageDescription - 与应用共享锻炼数据.
我添加了该密钥并再次上传.
现在应用程序拒绝了这个原因.
设计 - 4.2.1应用程序使用的HealthKit或CareKit API,但并不表示你的应用程序与应用生集成.
任何想法我怎么批准它?
我在Windows 8.1中更新了cordova到7.0.1在使用此命令添加平台创建项目后
cordova platform add android
Run Code Online (Sandbox Code Playgroud)
它给了我以下错误
Using this version of Cordova with older version of cordova-android is deprecated. Upgrade to cordova-android@5.0.0 or newer.
Error: Your android platform does not have Api.js
Run Code Online (Sandbox Code Playgroud)
我试图在论坛上搜索它,但没有解决它.
我在我的应用程序中使用日期选择器
当我单击按钮时,它从日期选择器中选择日期并将其设置为文本字段
set.addEventListener('click',function(e){
textfield.setValue(picker.value);
});
Run Code Online (Sandbox Code Playgroud)
它设置日期为2016-02-29 18:30:00 +0000但我想要它29-02-2016
我该如何更改日期格式?
android ×1
angular7 ×1
appcelerator ×1
cordova ×1
healthkit ×1
ionic4 ×1
ios ×1
javascript ×1
meteor ×1
session ×1
typescript ×1