小编Dam*_*ams的帖子

多个路由器出口丢失url参数

我正在构建一个应有两个特定路由器出口的angular 6应用程序:

<router-outlet name="navbar"></router-outlet>
<router-outlet></router-outlet>
Run Code Online (Sandbox Code Playgroud)

该应用程序由URL中指定的令牌驱动:

http://my.app/*token*/dashboard
Run Code Online (Sandbox Code Playgroud)

所以我有这个特定的路由:

const routes: Routes = [
    {
        path: ':token', component: CoreComponent, children: [
            { path: 'dashboard', component: DashboardComponent },
            { path: 'app1', component: App1Component },
            { path: 'app2', component: App2Component },
            { path: '', component: NavbarComponent, outlet: 'navbar' }
        ]
    }
];

@NgModule({
    imports: [
        CommonModule,
        RouterModule.forRoot(routes)
    ],
    exports: [RouterModule],
    declarations: []
})
Run Code Online (Sandbox Code Playgroud)

在每个组件中,我都从URL中检索token参数并对其进行一些检查。

constructor(public route: ActivatedRoute,
    public router: Router) {

}

ngOnInit() {
    this.route.params.subscribe(params => {
        let _token: string = …
Run Code Online (Sandbox Code Playgroud)

routing router-outlet angular angular6

3
推荐指数
1
解决办法
1525
查看次数

Angular 6 Filter observable array with pipe

我在 ngFor 循环中显示一个对象列表,我想用管道过滤这个列表。

我的研究使我想到了这一点:

filter-by.pipe.ts:

import { Pipe, PipeTransform } from '@angular/core';
import { UserLink } from '../_models/user-link';

@Pipe({
    name: 'filterBy'
})
export class FilterByPipe implements PipeTransform {
    transform(items: User[], isActive: boolean): any {
        if (!items) { return []; }
        return items.filter(x => x.isActive === isActive);
    }
}
Run Code Online (Sandbox Code Playgroud)

在 my.component.html 中:

<tr *ngFor="let item of items$|async|filterBy: {isActive: false}">
    <td>{{item.firstname}}</td>
    <td>{{item.lastname}}</td>
    <td>{{item.age}}</td>
</tr>
Run Code Online (Sandbox Code Playgroud)

但结果不是我所期望的:我的数组是空的。

我想念什么才能让它发挥作用?

我在这个 stackblitz ( https://stackblitz.com/edit/angular-46atle ) 中尝试了我的解决方案并且它有效。但我仍然无法让它在我的项目中工作。我检查了对象的属性和代码的其余部分,但看不到我的错误在哪里

[编辑]

问题解决了!我正在过滤的对象和我认为我正在过滤的对象之间缺少一个演员表。!初学者的错误!

感谢您的建议!

observable ngfor angular-pipe angular

0
推荐指数
1
解决办法
7908
查看次数