【发布时间】:2019-06-24 08:00:02
【问题描述】:
我开发了这个应用程序 (http://www.anelmad.com),并尝试在提交(Enter 或按钮单击)时将信息显示(单词的字典定义)重定向到另一个页面。
重定向有效,但页面内容不跟随。
在 home.component.html 中:
<form #myForm>
(...)
<input type="text" class="form-control" #elem
(keyup)="onNameKeyUp(elem.value)"
[ngModelOptions]="{standalone: true}"
[(ngModel)]="latinButton"
(focus)="onNameKeyUp(elem.value)"
placeholder="Enter"/>
<span class="input-group-append">
<button class="btn btn-outline-secondary" type="submit"
(click)="getWordList()">
<i class="fa fa-search"></i>
</button>
</span>
在这个表格之后,我补充说:
<router-outlet></router-outlet>
在 home.component.ts 中,我添加了 (this.router.navigate) 和新页面作为参数:
getWordList(){
this.router.navigate(['/words']);
this.webservice.getWords(this.spelling, this.selected)
.subscribe((res: Array<Word>)=> {
(...)
在 app.module 中:
const myRoutes: Routes=[
{path: 'words', component: WordsComponent},
{path: 'about', component: AboutComponent},
{path: 'home', component: HomeComponent},
{path: '', redirectTo: '/home', pathMatch:'full'},
{path: '**', redirectTo: '/home', pathMatch:'full'
]
如何将要显示的信息从表单传递到新页面(words.component.html)?
【问题讨论】:
标签: angular redirect routes components