Angular 属性指令获取对其他兄弟属性引用的引用

Angular attribute directive get reference to other sibling attribute reference

我正在尝试定义一个名为 pagingContext 的属性指令,它应该补充 angular material 排序指令 matSort 的功能。

我的想法是将元素定义为:

<table matSort [pagingContext]="pagingContext">

和类似这样的指令:

@Directive({
  selector: '[matSort] [pagingContext]'
})
export class MatSortPagingContextDirective {    
  constructor(private sort: MatSort) { }
}

我遇到的问题是上面的例子 returns 一个错误说

No provider found for MatSort

我在这里做错了什么?有没有办法实现对同级 MatSort 指令的引用?

谢谢和最诚挚的问候

声明您的 MatSortPagingContextDirective 的模块需要导入 MatSortModule:

import {MatSortModule} from '@angular/material/sort';

此外,您的选择器在我认为您可能希望删除的属性之间有一个 space。