小编Bar*_*ndo的帖子

命名的出口组件加载到根组件中

我正在尝试使用辅助路由实现sidenav,但没有成功.

这是我的路由器的简化示例:

{
        path: 'admin',
        component: MainLayoutComponent,
        children: [
            {
                path: '',
                component: ReportsPageComponent
            },
            {
                path: ':userID',
                component: ReportsUserPageComponent,
                resolve: {userID: UserIDResolver},
                children: [
                    {
                        path: 'day-detail/:day',
                        outlet: 'sidenav',
                        component: DayDetailComponent,
                        resolve: {dayRange: DayRangeResolver},
                    },
                ]
            },
        ]
    }
Run Code Online (Sandbox Code Playgroud)

main-layout.component.html:

<div class="content">
    <router-outlet></router-outlet>
</div>
<router-outlet name="sidenav"></router-outlet>
Run Code Online (Sandbox Code Playgroud)

然后在ReportsUserPageComponent中导航

this.router.navigate(['./', { outlets: { sidenav: ['day-detail', new Date().toJSON()] } }], { relativeTo: this.route });
Run Code Online (Sandbox Code Playgroud)

这创造了这样的东西

admin/9/(sidenav:day-detail/2018-06-22T13:28:11.737Z)
Run Code Online (Sandbox Code Playgroud)

问题是它不想加载DayDetailComponent.我需要这个作为ReportsUserPageComponent的子项,因为我不想要这样的东西,admin/(9//sidenav:day-detail/2018-06-20T22:00:00.000Z)因为我回去后,那些括号保留在那里(admin/(9))没有明显的原因.

angular-routing angular angular-router angular6

7
推荐指数
0
解决办法
313
查看次数

Angular 5 Http Interceptor刷新JWT令牌

我已经实现了令牌保存,检索和我也有刷新调用的逻辑.问题是,当我在我的HttpInterceptor中拦截403时,同时进行的其他调用也会刷新令牌.在我的令牌刷新之前,我很想接听这些电话.创建我称之为"信号量"的请求.

@Injectable()
export class TokenInterceptor implements HttpInterceptor {

private auth: AuthService;

constructor(private injector: Injector) {
}

intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    this.auth = this.injector.get(AuthService);

    if(this.auth.isAuthenticated()){
        request = request.clone({
            setHeaders: {
                Accept: 'application/json',
                Authorization: `Bearer ${localStorage.getItem('access_token')}`
            }
        });
    } else {
        request = request.clone({
            setHeaders: {
                Accept: 'application/json'
            }
        });
    }

    return next.handle(request).catch(error => {
        if (error.status === 401) {
            console.log('refreshing token');

            // TODO: return Refresh Token here and hold other calls
        }

        return Observable.throw(error);
    });
}
Run Code Online (Sandbox Code Playgroud)

angular-http-interceptors angular angular5

6
推荐指数
1
解决办法
4258
查看次数

无法使用 RxSwift 变量 asObservable() 设置 bind(to: UITableView)

我正在尝试绑定(到 :) 一个 collectionView,但 tableView 也不起作用。我有一个 viewModel,我的 Variable<[]> 在哪里,我想在值更改时使用我的 tableView 进行订阅。

viewModel.theVariable
        .asObservable()
        .bind(to: tableView.rx.items(cellIdentifier: "Cell", cellType: UITableViewCell.self)){
            (row, item, cell) in
            cell.textLabel?.text = item
        }
        .addDisposableTo(disposeBag)
Run Code Online (Sandbox Code Playgroud)

XCode 告诉我Type 'inout UITableView' does not conform to protocol 'ReactiveCompatible'应该是哪个,因为它适用于任何 UIView。

我已经尝试过使用它的 just() Observable 并且这种方法似乎可以正常工作。问题是我需要有一个变量,我在 viewModel 中设置了一个值,在 View 中我需要观察这个变化。不确定 Observable 是否提供此方法。

关键是这应该适用于变量吗?这是一个错误吗?我使用 Swift 3.2

uitableview ios swift rxdatasources

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