簡體   English   中英

表單字段/占位符和值

[英]Form fields / Placeholder and value

如果條件為真,我有一個要更改的表單字段。

<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;

有沒有辦法做到這一點。

感謝您的建議。

您可以使用三元運算符

<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'"/>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM