I have this form field which I want to change if a condition is true.
<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>
So I have one flag variable and if that is true I want to change the field placeholder and value into something.
$scope.isGoogleLoginWorking = true;
Is there any way for doing that.
Thanks in advice.
You can use a ternary operator
<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'"/>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.