在 Angular 8 中,我能够创建具有“@Injectable”属性的基础组件(对从中继承的实际组件进行类)。Angular 9 编译器告诉我:
组件 YourComponent 从 BaseComponent 继承其构造函数,但后者没有自己的 Angular 装饰器。依赖注入将无法解析 BaseComponent 的构造函数的参数。向 BaseComponent 添加 @Directive 装饰器,或向 RoleSelectDialogComponent 添加显式构造函数。
现在 Angular 9 做这些事情的方式是什么?这有效,但看起来有点hacky:
@Component({
selector: 'baseComponent',
template: 'no-ui'
})
Run Code Online (Sandbox Code Playgroud) 我已经看了不同的WCF服务行为(ConcurrencyModes/InstanceContextModes
)但是没有ConcurrencyMode
使用InstanceContextMode
"PerCall" 来区分"Single"/"Multiple ".任何人都可以帮我理解吗?
我知道在 TS 中实现 Union Types 是不可能的,这是绝对合理的。但我可能正在寻找类似的东西/其他:
type TypeA = { a: string, b?: string }
type TypeB = { a: string, c?: string }
type UnionType = TypeA | TypeB;
type IntersectionType = TypeA & TypeB;
// Error:
// A class can only implement an object type or intersection of object types with statically known members.(2422)
class UnionClass implements UnionType {
checkUnionProperties() {
let x: UnionType = { a: '' };
}
a = 'a';
}
//This is possible
class …
Run Code Online (Sandbox Code Playgroud) 我想问一下WPF是否具有binding
在绑定到“ object
” 类型的对象时可以在a上定义目标类型的任何功能。我有类型“的通用集合object
”,但必须为一个对象类型或其它(即进行处理DateTime
,int
在其各种结合点等)。
Type_X
在处理绑定时,有没有办法让我任意强制.Net框架在编译时视情况将未知类型的对象视为的对象?
出于性能原因,我的许多服务现在都返回 IQueryables,因此调用者可以在它们被具体化之前决定要过滤哪些元素。出于设计原因(接口等),我更愿意返回 IEnumerables,但这确实消除了 IQueryables 的优点:完整结果集的物化加上没有-Async方法。
我已经开始编写一些更喜欢 IQueryable 而不是 IEnumerable 的扩展方法,例如:
public static IEnumerable<TSource> Where<TSource>(this IEnumerable<TSource> source, Expression<Func<TSource, bool>> predicate)
=> source is IQueryable<TSource> ? Queryable.Where(source as IQueryable<TSource>, predicate) : Enumerable.Where(source, predicate.Compile());
public static Task<TSource[]> ToArrayAsync<TSource>(this IEnumerable<TSource> source)
=> (source as IQueryable<TSource>)?.ToArrayAsync() ?? Task.FromResult(source.ToArray());
Run Code Online (Sandbox Code Playgroud)
我不能是唯一一个思考这个问题的人。这些方法有什么改进吗?是否已经有一个很好的收藏/解决方案?或者这是一个糟糕的设计?所以请告诉我原因。
谢谢!
在我的组件中,我使用 ViewChildren 获取了其标记模板列表:
@ViewChildren(TemplateRef) private _templates: QueryList<TemplateRef<unknown>>;
Run Code Online (Sandbox Code Playgroud)
在 Angular8 中,我无法通过 Id 过滤它们,所以我需要寻找一个内部属性 - 这在某种程度上有点笨拙:
let template = this._templates.find(t => (<any>t)._def.references[id]) : null;
Run Code Online (Sandbox Code Playgroud)
现在,使用 Angular 9,这不再起作用。我检查了对象,发现了一个新的“黑客”:
this._templates.find(t => (<any>t)._declarationTContainer?.localNames?.includes(id)) : null;
Run Code Online (Sandbox Code Playgroud)
但是对于这种情况是否有任何新的或干净的解决方案?
仍然希望有一个没有自定义指令的解决方案,例如。MatTab 可能也会做类似的事情:
<mat-tab>
<ng-template mat-tab-label>
...
</ng-template>
<ng-template matTabContent>
...
</ng-template>
</mat-tab>
Run Code Online (Sandbox Code Playgroud) angular ×2
angular9 ×2
c# ×2
.net ×1
binding ×1
ienumerable ×1
iqueryable ×1
types ×1
typescript ×1
wcf ×1
wpf ×1