javascript - 如何使用 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 来做,但不知道怎么做,如果还有其他方法,请告诉我
谢谢!!
解决方案
您可以使用 ViewChild 指令来访问该元素。然后您可以记录它以查看所有可用信息。
export class AppComponent implements AfterViewInit {
@ViewChild('customCellTemplate') customCellTemplate : TemplateRef;
ngAfterViewInit() {
console.log(customCellTemplate);
}
}
我认为这种方式可以让您访问这些参数。
推荐阅读
- python-3.x - Python 创建一个可以使用 PIP 安装的本地包
- c# - Rust 游戏如何放置数百万的草、石和树
- reactjs - 为什么 useReducer 挂钩不更新状态?
- java - 传递给持久化的分离实体 - Spring API - @OneToOne 关系
- ios - NFC 标签 ISO 14443-3A 类型的读取标签命令是什么
- java - 抽象模式类型“实体”未知
- sql - 选择最后一组连续行中的第一行
- python - 在matlab中使用py运行python代码时重定向stdin和stdout的问题
- javascript - 如何在 JavaScript 中关闭窗口时运行方法
- linux - 在使用 GCC 编译 Linux 内核时对各种 intel 处理器使用 mtune=intel