[英]how to increment variable value in angular template
我是 angular 新手,想在 JAVA 中打印时增加值,如下所示:
<% int count=1; %>
<%=count++%> This is line with Text
<%=count++%> This is another line with different text
<%=count++%> This is line with different text
<%=count++%> This is last line
也许这只能在带有一些奇怪的 ngIf hacks 的 html 中完成,但这可能不是要走的路。
相反,您可以使用这样的文本在*.component.ts
中声明一个数组
lines = [
'This is line with Text',
'This is another line with different text',
'This is line with different text',
'This is last line',
];
并在*.component.html
.component.html 中执行 *ngFor
<div *ngFor="let line of lines; let index = index">{{ index + 1 }}: {{line}}</div>
它将输出:
<div>1: This is line with Text</div>
<div>2: This is another line with different text</div>
<div>3: This is line with different text</div>
<div>4: This is last line</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.