我有这个表单字段,如果条件为真,我想要更改。
<input type="email"
name="UserEmail"
id="UserEmail"
class="form-control"
ng-class="{'invalid-signup': signUpForm.UserEmail.$invalid && signUpForm.UserEmail.$dirty, 'valid-signup': signUpForm.UserEmail.$valid && signUpForm.UserEmail.$dirty}"
placeholder="Primary contact email."
ng-required="true"
ng-maxlength="30"
ng-minlength="5"
ng-model="signUpModel.UserEmail"/>
<div ng-show="signUpForm.UserEmail.$dirty && signUpForm.UserEmail.$invalid">
<p ng-show="signUpForm.UserEmail.$error.required">Email is required.</p>
<p ng-show="signUpForm.UserEmail.$error.pattern">Email is not valid.</p>
<p ng-show="signUpForm.UserEmail.$error.minlength">Email is too short, min 5 characters.</p>
<p ng-show="signUpForm.UserEmail.$error.maxlength">Email is too long, max 30 characters.</p>
</div>
所以我有一个标志变量,如果这是真的,我想将字段占位符和值更改为某些内容。
$scope.isGoogleLoginWorking = true;
有没有办法做到这一点。
感谢您的建议。
答案 0 :(得分:1)
您可以使用三元运算符
<input type="email"
name="UserEmail"
id="UserEmail"
class="form-control"
ng-class="{'invalid-signup': signUpForm.UserEmail.$invalid && signUpForm.UserEmail.$dirty, 'valid-signup': signUpForm.UserEmail.$valid && signUpForm.UserEmail.$dirty}"
placeholder="{{isGoogleLoginWorking?'Primary contact email.':'Something else'}}"
ng-required="true"
ng-maxlength="30"
ng-minlength="5"
ng-model="signUpModel.UserEmail" ng-value="isGoogleLoginWorking?signUpModel.UserEmail:'Something else'"/>