使用 ABP 框架从 Angular UI 隐藏功能

Hide feature from Angular UI with ABP Framework

我已经在 ABP 框架中创建了几个功能,但现在我想在 Angular 字体结束 UI 选项禁用时隐藏一个按钮。

我找到了 C# 代码的代码:

public class ReportingAppService : ApplicationService, IReportingAppService
{
    private readonly IFeatureChecker _featureChecker;

    public ReportingAppService(IFeatureChecker featureChecker)
    {
        _featureChecker = featureChecker;
    }

    public async Task<PdfReportResultDto> GetPdfReportAsync()
    {
        if (await _featureChecker.IsEnabledAsync("MyApp.PdfReporting"))
        {
            //TODO...
        }
        else
        {
            //TODO...   
        }
    }
}

但是AngularUI没有相等的代码。

最后一定是这样:

<button *ngIf="featureChecker.IsEnabled('MyApp.PdfReporting')">Download PDF</button>

您可以使用此代码:

// Global variable
feature = false;

constructor(
    private oAuthService: OAuthService, 
    private authService: AuthService,
    private configStateService: ConfigStateService
) { }

ngOnInit(): void {
    this.feature = this.configStateService.getFeature('MyApp.PdfReporting') === 'true';
}

它 returns 是一个字符串,但如果使用 ToggleStringValueType 作为特征,它总是 'true''false'.

在HTML里面你可以使用这个代码:

<button *ngIf="feature">Download PDF</button>