[英]How to display an input box even if no matching records
There are 5 books in my database. 我的数据库中有5本书。 Only 3 of them have a price.
其中只有3个有价格。 How can I still show an input box if there's no price in the database?
如果数据库中没有价格,如何仍显示输入框? Code below only creates an input box if there is a matching Id in books and bookPrices table.
如果在book和bookPrices表中存在匹配的ID,则下面的代码仅创建一个输入框。 Im a beginner, if possible please use my sample code when answering.
我是初学者,如果可能,请在回答时使用我的示例代码。 :-)
:-)
I have 5 books. 我有五本书。 Only books 1, 3 & 5 has a price.
只有书籍1、3和5有价格。 There will be no input box on Items 2 & 4. I want all of them to have an input box so that the user can enter a price and save it.
在项目2和4上将没有输入框。我希望所有这些都具有一个输入框,以便用户可以输入价格并将其保存。
<div ng-repeat="book in books">
<div>
<label>{{ book.Name }}</label>
<div ng-repeat="price in bookPrices | filter : { bookId : book.bookId } ">
<div>
<input type="text" class="form-control" name="val" ng-model="price.Value" maxlength="100">
</div>
</div>
</div>
</div>
You can use an angular condition to show the input box if there is no value. 如果没有值,则可以使用角度条件显示输入框。 Replace lines 4 and 5 with the below code.
用下面的代码替换第4行和第5行。
<span>{{price.Value}}</span>
<div ng-if="price.Value == "" || price.Value == undefined">
<input type="text" class="form-control" name="val" ng-model="price.Value" maxlength="100">
</div>
Alternatively, if you're using an angular version older than 1.1.5
you can use ng-show
. 另外,如果您使用的角版本早于
1.1.5
,则可以使用ng-show
。
<span>{{price.Value}}</span>
<div ng-show="price.Value == "" || price.Value == undefined">
<input type="text" class="form-control" name="val" ng-model="price.Value" maxlength="100">
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.