小编Ser*_*kiy的帖子

如何从具有mat-slider属性的display中的组件获取值

我正在使用Angular Material v6文档说它displaywith是“将在其显示在拇指标签中之前用于格式化该值的函数”。它应该这样使用:

<mat-slider thumbLabel [displayWith]="formatRateLabel" [value] = 'movie.mark'>
</mat-slider>
Run Code Online (Sandbox Code Playgroud)

在我的组件类中,我有一个formatRateLabel函数:

formatRateLabel(value: number) {
        if (!value) 
          return 0;
        return "HI!"; //just for demonstration
      }
Run Code Online (Sandbox Code Playgroud)

我需要从该函数内部获取组件的值。我通常通过this在某些函数中使用关键字来执行此操作。但是,当我从该fornatRateLabel组件中执行该功能时,组件的属性是不确定的。据我了解,这是一种范围问题。this此功能中的Word 只能访问mat-slider的所有属性和功能。但是我需要从该函数访问组件的属性。让我展示一下:这是我的组件:

@Component({
    templateUrl: './movieLibrary.component.html',
    styleUrls: ['./movieLibrary.component.css']
})
export class MovieLibraryComponent{
    someProperty : boolean = true;

    formatRateLabel(value: number){
    var myLocalVariable = this.someProperty;// debug showed it's as undefined. Why? 
   }
}
Run Code Online (Sandbox Code Playgroud)

我试图传递一些参数来formatRateLabel 像这样

[displayWith]="formatRateLabel(movie.mark)" 
Run Code Online (Sandbox Code Playgroud)

但在这种情况下,拇指标签将变为空,因此也无法使用。

有什么建议么?

typescript angular-material angular

5
推荐指数
2
解决办法
1917
查看次数

C# 中“is { }”语法是什么意思?

在过去的几周里,我开始在 C# 中遇到这种新语法:

if (someObj is { })  
{    
    do some stuff 
}
Run Code Online (Sandbox Code Playgroud)

所以它返回布尔值。看起来有点像 JavaScript。但这项检查到底有什么作用呢?和这个一样吗?

if (someObj == null)
{
    do some stuff
}
Run Code Online (Sandbox Code Playgroud)

我知道新版本的 C# 包含很多语法糖。这是其中的一部分吗?它有名字或什么吗?例如,我知道这?:被称为三元运算符,并且?.被称为 Elvis 运算符。但什么是is { }?甚至是运营商吗?

is { }是的,我在提问之前尝试过在线搜索,但由于请求中的大括号,谷歌似乎拒绝找到任何有关语法的有用信息。

c#

5
推荐指数
1
解决办法
356
查看次数

标签 统计

angular ×1

angular-material ×1

c# ×1

typescript ×1