Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.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
Angular 如何使用角度datepipe从数字中获取monthname_Angular_Date Pipe - Fatal编程技术网

Angular 如何使用角度datepipe从数字中获取monthname

Angular 如何使用角度datepipe从数字中获取monthname,angular,date-pipe,Angular,Date Pipe,我想使用angular的datepipe显示包含本地化月份名称的下拉列表 <select> <option *ngFor="let month of months;" value="{{month}}"> {{month | date: 'MMMM'}} </option> </select> 我的代码有什么问题吗?或者使用angular的datepipe完全不可能实现我想

我想使用angular的datepipe显示包含本地化月份名称的下拉列表

<select>
    <option *ngFor="let month of months;" value="{{month}}">
         {{month | date: 'MMMM'}}
    </option>
</select>

我的代码有什么问题吗?或者使用angular的datepipe完全不可能实现我想要的功能吗?如果是这样,我该如何完成它呢?

月份必须是一组日期,您可以使用

months=[0,1,2,3,4,5,6,7,8,9,10,11].map(x=>new Date(2000,x,2))
我将[value]改为[value]=I

<select>
    <option *ngFor="let month of months;let i=index" [value]="i">
         {{month | date: 'MMMM'}}
    </option>
</select>

月份必须是日期数组,您可以使用

months=[0,1,2,3,4,5,6,7,8,9,10,11].map(x=>new Date(2000,x,2))
我将[value]改为[value]=I

<select>
    <option *ngFor="let month of months;let i=index" [value]="i">
         {{month | date: 'MMMM'}}
    </option>
</select>
从中可以看出,日期管道的输入是以下内容之一:

日期表达式:日期对象、UTC历元后的毫秒数或ISO字符串

因此,0-11的输入被解释为01之后的毫秒。1970年1月。因此,它们都在一月份。 您可能应该创建一个日期对象数组以用作月份[]。

从中可以看出,日期管道的输入是以下内容之一:

日期表达式:日期对象、UTC历元后的毫秒数或ISO字符串

因此,0-11的输入被解释为01之后的毫秒。1970年1月。因此,它们都在一月份。 您可能应该创建一个日期对象数组,用作月份[]