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

jjjwad0x  于 2022-12-24  发布在  TypeScript
关注(0)|答案(2)|浏览(104)

我用的是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;
}

在www.example.com中定义https://manfredsteyer.github.io/angular-oauth2-oidc/docs/classes/AuthConfig.html#source
我该怎么撤销它?

oxcyiej7

oxcyiej71#

创建自定义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;
     }
}

并使用这个类

ltskdhd1

ltskdhd12#

你可以这样做:

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

相关问题