Angular 角度省道中的对象运行时类型

Angular 角度省道中的对象运行时类型,angular,dart,angular-dart,Angular,Dart,Angular Dart,我有一个组件,它提供了一个模型对象,这个模型对象可以有几种类型,它的类型决定了将在其中呈现什么组件: <div [ngSwitch]="poolModel.runtimeType.toString()"> <template ngSwitchCase="CryptonoteMiningPool"><cryptonote-pool [model]="poolModel"></cryptonote-pool></template>

我有一个组件,它提供了一个模型对象,这个模型对象可以有几种类型,它的类型决定了将在其中呈现什么组件:

<div [ngSwitch]="poolModel.runtimeType.toString()">
    <template ngSwitchCase="CryptonoteMiningPool"><cryptonote-pool [model]="poolModel"></cryptonote-pool></template>
    <template ngSwitchCase="DaggerHashimotoMiningPool"><dag-hash-pool [model]="poolModel"></dag-hash-pool></template>
</div>

这在调试模式下工作得很好,但一旦我编译发行版runtimeType总是返回“fS”

我有一个解决方案,基本上是在模型中设置一个常量并查看它,但是如果我可以避免它,我宁愿没有这样的麻烦,因为我可能需要维护许多类型的模型


有没有一种方法可以让runtimeType返回我在发布模式下所期望的结果?

运行时类型不是我用于程序逻辑的东西。它会根据编译器选项进行更改,实际上,甚至使用它也会使应用程序(在dart2js中)的优化更加困难

我们禁止在dart2js性能指南中使用它

您最好创建某种基类:

abstract class DynamicRender {
  String get renderType;
}

让您的类扩展/混合/实现并使用它。

这就是我的想法。谢谢:(解释也很有用