我試圖在按鈕單擊上顯示/隱藏元素。以下是我迄今爲止編寫的代碼。由於缺乏知識,我在編寫Angular代碼時遇到了麻煩。在按鈕上單擊角度顯示隱藏元素
我想實現的是:我有3個文本框,默認情況下,默認情況下會顯示3個文本框,只要用戶點擊+
按鈕即可。第二個文本框將可見,第三個相同。要刪除框,我創建了一個-
按鈕。所以,一旦用戶點擊-
按鈕,最後一個框將被隱藏。
<div class="col-xs-10"><div class="topjob_resumetitle" ng-class="{ 'has-error' : errorcity }">
<input name="city" id="city" type="text" class="form-control textbox1 txt-auto" required="required" placeholder="Job Location* " ng-model="formData.city">
<div class = "errorba" ng-show="errorcity">{{errorcity}}</div>
</div></div>
<div class="col-xs-2">
<button class="remove" ng-click="removeChoice()">-</button>
</div>
<button class="addfields" ng-click="addNewChoice()">+</button><br>
<div class="col-xs-10"><div class="topjob_resumetitle" ng-class="{ 'has-error' : errorcity1 }">
<input name="city1" id="city1" type="text" class="form-control textbox1 txt-auto" required="required" placeholder="Job Location* " ng-model="formData.city1">
<div class = "errorba" ng-show="errorcity">{{errorcity1}}</div>
</div></div>
<div class="col-xs-2">
<button class="remove" ng-click="removeChoice()">-</button>
</div>
<button class="addfields" ng-click="addNewChoice()">+</button><br>
<div class="col-xs-10"><div class="topjob_resumetitle" ng-class="{ 'has-error' : errorcity }">
<input name="city2" id="city2" type="text" class="form-control textbox1 txt-auto" required="required" placeholder="Job Location* " ng-model="formData.city2">
<div class = "errorba" ng-show="errorcity2">{{errorcity2}}</div>
</div></div>
<div class="col-xs-2">
<button class="remove" ng-click="removeChoice()">-</button>
</div>
<button class="addfields" ng-click="addNewChoice()">+</button>
我在addNewChoice()和removeChoice()下沒有任何東西。
它看起來就像你知道的'NG-show'指令。你能想出一種使用它來隱藏或顯示基於範圍屬性的東西嗎?那麼你可以改變你的方法中的屬性? –