我使用angular-ui-mask以123-45-6789格式显示ssn,但是当输入框失去焦点时我还想隐藏前5个字符,并在输入框获得焦点时显示所有数字。
我的HTML
<input class="btnDropdown"
id="phoneTextInput"
ui-mask="{{uimaskpattern}}"
ui-mask-placeholder-char=""
ng-focus="applymask()"
ng-blur="phoneForm['Phone_'+$index].$viewValue = removemask(contact.contactDetails.attributeDetails.contact)"
md-minlength="10"
md-maxlength="10"
name="Phone_{{$index}}"
ng-model="contact.contactDetails.attributeDetails.contact">
Angular Code:
uimaskpattern的初始值=&#34; 999-99-9999&#34;
//When input gets focus
public applymask() {
this.uimaskpattern = "999-999-9999";
}
//When input loses focus
public removemask(ssn) {
if (ssn) {
console.log(ssn);
this.uimaskpattern = "XXX-XXX-9999";
let formstring = 'XXX-XXX-'+ssn.slice(6, ssn.length);
console.log(formstring);
return formstring;
}
}
我面临的问题是,在模糊时,如果用户输入123456789,则在模糊时文本变为XXX-XX-1234,而不是XXX-XX-6789,即代替6789,附加的数字是前4,如果我只是用{{}}打印返回的字符串,它就会正确显示
答案 0 :(得分:0)
更改ng-blur,如下所示
String
并删除掩码功能如下并立即检查。它可能有效
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<skip>false</skip>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>