我正在尝试使用APP_INITIALIZER
执行我的saveURL方法,但是我的saveURL方法却出错了。
错误TypeError:无法读取未定义的属性'setCookie'
App.modulte.ts
...
export function saveUrl(dualLogonService: DualLogonService) {
console.debug('Executing saveUrl');
return (): Promise<any> => {
dualLogonService.setCookie(); //THIS IS WHAT GIVES ME ERROR
return null;
};
}
...
providers: [
...
{
provide: APP_INITIALIZER,
useFactory: saveUrl,
deps: [DualLogonService],
multi: true
}
]
DualLogonService.ts
import { Injectable } from '@angular/core';
import { Router, CanActivate } from '@angular/router';
import { AuthenticationService } from '@sec/security';
import { appConfigMapping } from 'src/environments/app.config.mapping';
import { of } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class DualLogonService implements CanActivate {
...
constructor(
private router: Router,
private authService: AuthenticationService
) {}
..
setCookie(): void {
document.cookie = 'Deeplink' + '=' + this.router.url + ';path=/';
}
答案 0 :(得分:1)
将DualLogonService添加到Providers数组