相关疑难解决方法(0)

Angular - 在服务和组件中使用管道

在AngularJS中,我能够使用类似于此的语法在服务和控制器内部使用过滤器(管道):

$filter('date')(myDate, 'yyyy-MM-dd');
Run Code Online (Sandbox Code Playgroud)

是否可以在Angular中使用像这样的服务/组件中的管道?

angular

306
推荐指数
8
解决办法
21万
查看次数

如何在Angular2中添加日期?

我只是想创建一个从现在起3天的日期,用于打字稿角度组件.

我看过Angular2时刻,但这似乎只与管道有关.虽然我确实看到这篇关于在代码中使用管道的文章,看起来有点hacky ......

也许我错过了一些东西,因为这应该很简单?!

谢谢

typescript angular2-moment angular

14
推荐指数
1
解决办法
3万
查看次数

Angular2 - 在被动表单上设置日期字段

我有一个使用两个日期字段的组件,一个开始日期和结束日期.

默认情况下,我禁用了结束日期字段,并在选择开始日期时切换它.

this.transitionForm = this.fb.group({
 effectiveEndDate: [{ value: '', disabled: true }]
 ..... 
});
Run Code Online (Sandbox Code Playgroud)

我试图在我的代码中设置此结束日期字段的值.

this.transitionForm.controls['effectiveEndDate'].setValue(this.utils.currentDate());
Run Code Online (Sandbox Code Playgroud)

实用功能:

/**
 * Returns the current date
 */
currentDate() {
    const currentDate = new Date();
    const day = currentDate.getDate();
    const month = currentDate.getMonth() + 1;
    const year = currentDate.getFullYear();
    return month + "/" + day + "/" + year;
}
Run Code Online (Sandbox Code Playgroud)

HTML:

<input type="date" class="form-control input-sm" id="effectiveEndDate" name="effectiveEndDate" placeholder="Required" formControlName="effectiveEndDate">
Run Code Online (Sandbox Code Playgroud)

出于某种原因,该领域没有得到更新.

我也尝试使用PatchValue,但也没有设置它.

我错过了什么?

typescript angular

8
推荐指数
3
解决办法
3万
查看次数

标签 统计

angular ×3

typescript ×2

angular2-moment ×1