我呼籲NG-KEYUP功能,並試圖通過實際上未得到通過的文本框的值,並得到「未定義」可變訪問角度js 1中的文本框值問題?
HTML代碼
<md-input-container class="md-icon-float md-block">
<label >First Name </label>
<md-icon md-font-icon="icon-account" class="name"></md-icon>
<input type="fname" id="fname" name="fname" ng-value = "{{vm.form.fname}}" ng-model="vm.contact.fname" ng-pattern="/^[a-zA-Z ]{2,30}$/" type="text" ng-keyup = "vm.firstLetterCaps('fname',vm.form.fname)" required>
<div ng-messages="contactForm.fname.$error" role="alert">
<div ng-message="required">
<span>First name is required</span>
</div>
<div ng-message="pattern">
<span>First name must be a valid </span>
</div>
</div>
</md-input-container>
控制器代碼功能
function firstLetterCaps(textboxid, str){
console.log(textboxid)
console.log(str)
// string with alteast one character
if (str && str.length >= 1)
{
var firstChar = str.charAt(0);
var remainingStr = str.slice(1);
str = firstChar.toUpperCase() + remainingStr;
}
if()
document.getElementById(textboxid).value = str;
}
只是爲了澄清,你需要一個'NG-value'什麼,當你有一個'NG-model'? – lealceldeiro
我已經嘗試過,但在控制檯中獲得了未定義的值。 – SaMeEr