angular - Typescript 函数不运行由 Parent 传递的 Child 触发的局部变量
问题描述
我的代码有问题。当我在 C# 中执行此操作时,它可以工作,但在打字稿中它不会。我有一个组件用作组件的构建器,在这种情况下是一个可供不同组件使用的列表,问题是我可以将函数从父级传递给子级,并且它是由子级触发的,但是parent 全部未定义或为空。
这是我的代码:
主要模块.ts:(父)
testVar: string = 'testing';
GotoSalesOrder(event: any) {
console.log(event); // not null since its a parameter
console.log(this.testVar); // null or undefiend
this.router.navigate(['sales-order-header', {id: event}]); // is declared in constructor, and this.router is undefined
}
let rows: any[] = [
{
type: 'checkbox',
variableName: 'testcheckbox',
},
{
type: 'button',
variableName: 'test1Var',
OnClick: this.OnClickFunction
},
{
type: 'text',
variableName: 'test2Var'
},
{
type: 'text',
variableName: 'test3Var'
}
];
主模块.html:(父)
<app-table-list [tableContents] = "tableContents"></app-table-list>
app-table-list.ts:(儿童)
@Input() tableContents: TableContents = new TableContents();
app-table-list.html:(儿童)
<button *ngIf = "data.type == 'button'" class="btn btn-link" (click)="data.OnClick(row[data.variableName])">
TableContents.ts 类:
rows: any[] = [];
解决方案
推荐阅读
- angular - 如何根据可观察值设置primeng表的默认排序顺序
- html - 带有垂直滚动条但带有固定标题的 HTML+CSS 表格
- ajax - ajax laravel更新功能中的列不能为空
- oracle - 如何将数据保存在不同的列中,而不是替换同一列中的数据
- javascript - React Typescript 使用LocalStorage Hook
- python - curve_fit TypeError: 输入不当:N=2 不得超过 M=1
- appium-android - AWS Device Farm 测试用例失败
- lambda-calculus - 在谈论 lambda 演算时,postcompose 是什么意思?
- bash - 如何将 terragrunt apply 的输出变量保存为常规 shell 环境变量?
- java - J2ssh 获取空输入流