Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Angular2组件的HTML模板中实现计数器_Html_Angular - Fatal编程技术网

在Angular2组件的HTML模板中实现计数器

在Angular2组件的HTML模板中实现计数器,html,angular,Html,Angular,我正在尝试建立一个自定义日历。还有很多事情要做,但我的问题是如何在Angular2组件中的HTML模板中实现计数器。更具体地说: <div class="container"> <table class="table table-bordered"> <tbody> <tr *ngFor="let w of weeks"> <td *ngFor="let d of days">

我正在尝试建立一个自定义日历。还有很多事情要做,但我的问题是如何在Angular2组件中的HTML模板中实现计数器。更具体地说:

<div class="container">
  <table class="table table-bordered">
    <tbody>
        <tr *ngFor="let w of weeks">
            <td *ngFor="let d of days">
                <ng-container *ngIf="(day_count <= monthLength && (w > 1 || d >= firstDayOfMonth))">
                    {{ day_count }}
                    // On this point, I want "day_count = day_count + 1"...
                </ng-container>
            </td>
        </tr>
    </tbody>
 </table>
</div>

变量“day_count”是负责显示每月每个日期的变量。最初,它必须是1,然后增加1,以此类推,直到达到月长。那么,我该如何实现呢???

你不能这样做没有模板方面

但我认为您的代码需要的解决方案是:

模板侧:

<div class="container">
  <table class="table table-bordered">
    <tbody>
        <tr *ngFor="let w of weeks">
            <td *ngFor="let d of days">
                <ng-container *ngIf="incr(w,d,monthLength,firstDayOfMonth)">
                    {{ incr(w,d,monthLength,firstDayOfMonth) }}
                </ng-container>
            </td>
        </tr>
    </tbody>
 </table>
</div>

{{incr(w,d,monthLength,每月第一天)}
组件方面:

weeks = [1,2,3,4,5,6];
days = [0,1,2,3,4,5,6];
firstDayOfMonth = 0;
monthLength = 31;

incr(w,d,monthLength,firstDayOfMonth)
{
    let day_count = ((w-1)*7)+d;
    if (day_count < (monthLength+firstDayOfMonth)  && day_count >= firstDayOfMonth)
    {
        return day_count - firstDayOfMonth+1;
    }
}
weeks=[1,2,3,4,5,6];
天数=[0,1,2,3,4,5,6];
每月第一天=0;
月长=31;
增量(w、d、月长、月初一)
{
让天_计数=((w-1)*7)+d;
如果(日计数<(月长+月初一日)&日计数>=月初一日)
{
返回日\u计数-每月第一天+1;
}
}

您不能使用另一个
ngFor
循环吗?
weeks = [1,2,3,4,5,6];
days = [0,1,2,3,4,5,6];
firstDayOfMonth = 0;
monthLength = 31;

incr(w,d,monthLength,firstDayOfMonth)
{
    let day_count = ((w-1)*7)+d;
    if (day_count < (monthLength+firstDayOfMonth)  && day_count >= firstDayOfMonth)
    {
        return day_count - firstDayOfMonth+1;
    }
}