如何覆盖Angular中的方法?(版本8+)



我使用的是Angular 8。

我正在尝试覆盖以下内容的方法函数:

/**
* This property allows you to override the method that is used to open the login url,
* allowing a way for implementations to specify their own method of routing to new
* urls.
*/
public openUri?: ((uri: string) => void) = uri => {
location.href = uri;
}

定义于https://manfredsteyer.github.io/angular-oauth2-oidc/docs/classes/AuthConfig.html#source

如何覆盖它?

创建自定义AuthConfig

export class CustomAutConfig implements AuthConfig 
{
constructor(json?: Partial<AuthConfig>)
{
super(json);
}
//here override the functions simply declaring
public openUri?: ((uri: string) => void) = uri => {
location.href = uri;
}
}

并使用此类

你可以这样做:

const myConfig = new AuthConfig({
// Other config,
openUri: (uri: string) => {
// Your code go here
}
});

最新更新