[英]How to use angular material cdk stepper with a constructor
考慮以下代碼:
import { Component } from '@angular/core';
import { CdkStepper } from '@angular/cdk/stepper';
@Component({
selector: 'stepper-form',
templateUrl: './stepper-form.component.html',
styleUrls: ['./stepper-form.component.scss'],
providers: [{ provide: CdkStepper, useExisting: StepperFormComponent }]
})
export class StepperFormComponent extends CdkStepper {
constructor(){
super();
}
}
經過一番研究,我發現我需要使用super()
function。 當我在我的情況下使用它時,請參閱上面的 cpde,我收到一個錯誤:
預期 2-4 arguments,但得到 0。
在這種情況下,我需要使構造函數工作的 2-4 arguments 是什么?
只需添加:
constructor(
dir: Directionality,
changeDetectorRef: ChangeDetectorRef,
) {
super(dir, changeDetectorRef);
}
https://github.com/angular/components/blob/master/src/cdk/stepper/stepper.ts
我假設 Karolina 查找了構造函數,第 330 行。
這意味着所需的進口是:
import {Directionality} from '@angular/cdk/bidi';
import {ChangeDetectorRef} from '@angular/core';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.