【发布时间】:2018-07-07 01:00:50
【问题描述】:
我相信我正在尝试做的事情是微不足道的,但我尝试了很多不同的事情并且无法弄清楚。
我有两个组件,SearchComponent 和 DetailsComponent 显示搜索结果。
一个路由模块:
const routes: Routes = [
{ path: '', component: SearchComponent},
{ path: 'armory/:name', component: DetailsComponent}
];
@NgModule({
imports: [ RouterModule.forRoot(routes) ],
exports: [ RouterModule ]
})
export class AppRoutingModule {}
和search.component.html中的输入
<form class="form-inline container-fluid">
<input type="text" id="name" placeholder="Character name..." class="form-control">
<button (click)="onSearch( ... <!--name should be here-->)" class="btn">
<span class="fa fa-search"></span></button>
</form>
然后在search.component.ts:
export class SearchComponent implements OnInit {
constructor(private router: Router) {
}
onSearch(name: string) {
this.router.navigate(['/armory', name])
}
}
如何获取name 输入的值并将其作为参数传递给onSearch()?
【问题讨论】:
-
您使用的是什么类型的表格?模型驱动还是模板驱动?
标签: javascript angular routing