【发布时间】:2021-09-30 01:24:05
【问题描述】:
目前,我的 Angular 项目中的路线设置如下:
const routes: Routes = [
{ path: 'defect', component: AppComponent },
{ path: 'defect/:start', component: DefectComponent }
];
然后在我的 DefectComponent 的 TS 中我有:
//route is declared in my parameters as ActivatedRoute
ngOnInit(): void {
let temp = this.route.snapshot.paramMap.get('start');
if(temp) {
this.timestamp.TestStart = temp;
}
}
在我的 DefectComponent 的 html 中,我有:
<input id="TestStart" [(ngModel)]="timestamp.TestStart" placeholder="Time">
<button class="findSteps" (click)="createCases(timestamp)">
Find Failed Cases
</button>
我认为当我使用以下网址调用它时,它会使用“start”参数自动填充我的输入:
http://localhost:4200/defect/272020-02-06_0348100661PM
因为它已添加到 timestamp.TestStart onInit,但现在它仍然只是显示“时间”。关于我做错了什么有什么想法吗?
我已经有的想法:
- ngModel 是否位于 ngOnInit 之前?
- 我是否以某种方式将参数传递到 url 错误?
更新: temp 当前设置为 null 而不是输入。对此的任何想法将不胜感激。
【问题讨论】:
标签: angular typescript url routes ngmodel