在未设置输入类型的短信中获取otp后,未在值中设置
<ion-item>
<ion-label >OTP Code</ion-label>
<ion-input type="text" maxlength="4" id="smscode" minlength="4"
formControlName="password" placeholder="Your OTP Code"
value="{{smscode}}">
</ion-input>
</ion-item>
this.smscode=1234;
receiveSMS()
{
if(SMS)SMS.startWatch(function(){
document.addEventListener('onSMSArrive', function(e)
{
var sms = e.data;
if(sms.address=='IM-ODTMLT')
{
this.smscode=sms.body.substr(28,4);
alert( this.smscode);
alert(JSON.stringify(sms));
this.stopSMS();
}
});
},
function()
{
console.log('failed to start watching');
});
}
<ion-input type="text" maxlength="4" id="smscode" minlength="4"
formControlName="password"
placeholder="Your OTP Code" value="{{smscode}}">
</ion-input>
这是一个离子代码
答案 0 :(得分:0)
输入需要一个ngModel
指令:
<ion-input type="text" maxlength="4" id="smscode" minlength="4"
formControlName="password" placeholder="Your OTP Code"
̶v̶a̶l̶u̶e̶=̶"̶{̶{̶s̶m̶s̶c̶o̶d̶e̶}̶}̶"̶
[(ngModel)]="smscode">
</ion-input>