我使用以下数字管道来格式化数量:
{{tradcollapse?.quantity | number}}
Run Code Online (Sandbox Code Playgroud)
示例显示为 1,234,0.
我想在带过滤的组件中使用此格式数量,而不是数字,因为它是 12340。我该如何实现?
我正在尝试在我的多语言应用程序中使用 Kendo 组件。为了正确设置日期格式,Kendo 需要LOCALE_ID设置 Angular 的 。我不知道如何以干净的方式实现这一点。
目前,我正在使用 来HTTP_ACCEPT_LANGUAGE查找应该使用哪种语言来提供我的应用程序。我在nginx.conf中这样做:
# Parse AcceptLanguage header
# en,es,pl,fr
# en,es;q=0.8,pl;q=0.7,fr;q=0.6
set $first_language $http_accept_language;
if ($http_accept_language ~* '^(.+?),') {
set $first_language $1;
}
set $language_suffix 'en';
if ($first_language ~* 'fr') {
set $language_suffix 'fr';
}
root /usr/share/nginx/html/$language_suffix;
Run Code Online (Sandbox Code Playgroud)
这有效。使用正确的 .xlf 文件并且消息显示为已翻译。
现在,我需要设置LOCALE_ID以使我的 Kendo 组件以正确的格式呈现日期。我尝试通过获取浏览器当前语言来设置它。以下是我尝试实现这一目标的方法:
应用程序模块.ts
...
import { LOCALE_ID, NgModule } from '@angular/core';
import { LocaleService } from './shared/service/locale.service';
...
@NgModule({
declarations: [
...
],
imports: [ …Run Code Online (Sandbox Code Playgroud) 是否可以在单击按钮时更改/放置管道以格式化 Angular 2 中的特定列?例如,我有一个包含“名称”和“小时”列的表,当我单击按钮时,“小时”显示的数据应转换为天,反之亦然。
<button class="btn btn-secondary" (click)="convertToDays()">Days</button>
<button class="btn btn-secondary" (click)="convertToHours()">Hours</button>
<tbody>
<td>{{availableLeave.hours}}</td>
</tbody>
convertToDays(){
//put pipe to format availableLeave.hours to display as days ex.('48' hours should be displayed as '2' days)
}
convertToHours(){
//will just revert the original formatting of availableLeave.hours which is in hour format
}
Run Code Online (Sandbox Code Playgroud) 我希望以下列格式获取日期:YYYY-MM-DD.
我基于这个问题在Angular2中写了一个日期服务: 如何在JavaScript中获取当前日期?.
我想检查它是否是正确的实现,或者是否有更好的方法来实现目标.
import { Injectable } from '@angular/core';
@Injectable()
export class DateService {
private currentDate = new Date();
getCurrentDateInApiFormat(): string{
let day:any = this.currentDate.getDate();
let month:any = this.currentDate.getMonth() + 1;
let year:any = this.currentDate.getFullYear();
let dateInApiFormat: string;
if(day<10){
day = '0' + day.toString();
}
if(month<10){
month = '0' + month.toString();
}
dateInApiFormat = day + '-' + month + '-' + year.toString();
return dateInApiFormat;
}
}
Run Code Online (Sandbox Code Playgroud)