javascript - 如何使用 Angular 8 为对象数组提供不同的日期

标签 javascript angular

我在 angular8 应用程序中使用了 bootstarp 4 datetimepicker。在这里,我获取了所有 3 个字段中的最新日期,但我必须获取给该特定字段的日期。我已经使用了 ngModel,这个问题是基于此吗?

DEMO

TS:

dateRestriction(event, restriction) {
    $(".onlyDateTime").datetimepicker();
    $(".onlyDate").datetimepicker({ format: "L" });
    $(".onlyDateTime")
      .datetimepicker()
      .on("dp.change", e => {
        const date = e.date;
        console.log(e.date.format("L"));
        this.Restrictions[restriction].datetime = e.date.format("L");
      });
  }

HTML:

<div class="col-6 {{isReadOnly ? 'link-disabled' : ''}}"
            *ngFor="let restrictValue of Restrictions;let i = index">
            <div class="custom-control custom-switch">
              <input type="checkbox" class="custom-control-input" id="{{restrictValue.id}}"
                [checked]="restrictValue.boolValue" (change)="restrictValue.boolValue = $event.target.checked"
                >
              <label class="custom-control-label" for="{{restrictValue.id}}">{{restrictValue.label}}</label>
            </div>
            <div class="form-group">
              <input type="text" class="form-control onlyDateTime" placeholder="MM/DD/YYYY HH:MM AM/PM"
                [disabled]="!restrictValue.boolValue" [(ngModel)]="restrictValue.datetime" (change)="dateRestriction($event,restrictValue)" (click)="dateRestriction($event, i)"
                [ngModelOptions]="{standalone: true}" >
            </div>
          </div>

最佳答案

自从您使用 Jquery 日期选择器更改日期时间选择器事件以来。它在日期选择器的点击事件之前被调用。

试试这个

ngAfterViewInit() {
     $(".onlyDate").datetimepicker({ format: "L" });
      let dat = null;
       $(".onlyDate")
      .datetimepicker()
      .on("dp.hide", e => {
        const date = e.date;
         let dat = e.date.format("L");
        this.Restrictions[this.selectedIndex].datetime = dat;
      });
   }

  dateRestriction( i) {
    this.selectedIndex = i;
  }

Forked Example

关于javascript - 如何使用 Angular 8 为对象数组提供不同的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60276987/

相关文章:

javascript - React - 将点击处理程序附加到动态子项

javascript - jQuery Mobile 中的背景图像

javascript - 如何在 Angular 6 中实现选择下拉列表(按搜索过滤),如何按名称属性过滤对象

angular - 以 Angular 发送 Action 的正确方法是什么?

angular - 需要在 Angular 应用程序内播放视频文件

javascript - 如何按类获取元素? html单元

javascript - 在javascript中使用正则表达式查找字符串中最后一次出现的逗号

javascript - 获取嵌入式pdf的当前页码

angular - Strapi Microsoft 身份验证在 Angular 应用程序中存在重定向 URI 问题

javascript - 如何使用 Angular 动画使其始终朝一个方向移动?