首页 > 解决方案 > 如何使用 jquery 访问 ng-template 属性

问题描述

我正在使用带有自定义模板的角度日历,如下所示:https ://mattlewis92.github.io/angular-calendar/#/custom-templates

我的 html 中有 ng-template 元素

<ng-template #customCellTemplate let-day="day" let-viewDate="event"let-locale="locale" [let-status]="statuses">

并在我的 mwl-calendar-month-view 元素中调用 customCellTemplate

  <mwl-calendar-month-view [viewDate]="viewDate" [events]="events"   (eventClicked)="handleEvent('Clicked', $event.event)"
    [cellTemplate]="customCellTemplate">
  </mwl-calendar-month-view>

现在我想在我的 component.ts 文件中访问 day(在 ng-template - let-day="day" 中)

我想我可以用 jquery 来做,但不知道怎么做,如果还有其他方法,请告诉我

谢谢!!

标签: javascriptangulartypescriptangular-calendar

解决方案


您可以使用 ViewChild 指令来访问该元素。然后您可以记录它以查看所有可用信息。

export class AppComponent implements AfterViewInit {
  @ViewChild('customCellTemplate') customCellTemplate : TemplateRef;
  ngAfterViewInit() {
    console.log(customCellTemplate);
  }
}

我认为这种方式可以让您访问这些参数。


推荐阅读