【发布时间】:2019-09-11 14:38:42
【问题描述】:
我不知道为什么我的路由没有发生。
到目前为止
<table mat-table [dataSource]="searchResult_DS" class="mat-elevation-z8">
<ng-container [matColumnDef]="column" *ngFor="let column of displayedColumns">
<th mat-header-cell *matHeaderCellDef> {{column}} </th>
<td mat-cell *matCellDef="let element" > {{element[column]}} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"
[routerLink] = "['/show-this-user-page', row.custId]"
(click)=highlightSelectedRow(row) [ngClass]="{ 'bg-clr': row === selectedRow }">
</tr>
</table>
现在,我有一个包含数据列表的表格。每当用户选择特定行时,它应该导航到下一页
public highlightSelectedRow(row): void
{
this.picked = row.custId;
// i can able get values from here
//do i need to add below line here.?
//this.router.navigate(['/show-this-user-page']);
}
routing.ts
const routes: Routes = [
{
path: 'Here-where-am-doingStuffes',
canActivate: [AuthenticationGuard],
component: Here-where-am-doingStuffes
// this page landing with my mat-table- then am doing routing on row
},
{
path: 'sample route 1',
canActivate: [AuthenticationGuard],
component: sample-route-1
},
{
path: 'sample route 1',
canActivate: [AuthenticationGuard],
component: sample-route-2
},
{
path: 'second-main-data',
loadChildren: '/some-other-module/someother-data.module#SecondMainModule'
}
];
错误
ERROR 错误:未捕获(承诺):错误:模板解析错误: 无法绑定到“routerLink”,因为它不是“td”的已知属性。 ("标题单元格 *matHeaderCellDef> {{column}} ][routerLink] = "['/show-this-user', element.email]"> {{element[column]}} "): ng:///AdminModule/searchUser.html@35:51 错误:模板 解析错误:无法绑定到“routerLink”,因为它不是已知的 'td' 的属性。 ("标题单元格 *matHeaderCellDef> {{column}} ][routerLink] = "['/show-this-user', element.email]"> {{element[column]}} "): ng:///AdminModule/searchUser.html@35:51
谁能告诉我应该在哪里更改我的代码以及还需要添加什么?如果您分享工作演示会非常有帮助。
【问题讨论】:
-
通常该错误表明您没有在控件所在的模块中包含对 Angular
RoutingModule的引用。没有它,编译器不知道如何处理该指令。 -
我用一个例子在答案中添加了^^,希望这很酷
-
是的.. 正在我的本地进行更改。 ll,让你知道:)
-
好像 RoutingModule 没有注入到 appModule 中
-
已经全部注入了。
标签: javascript angular typescript angular2-routing