[英]Member should be declared before all private instance
private userSubject$: BehaviorSubject<UserModel> = new BehaviorSubject<UserModel>(null);
userChanged$: Observable<UserModel> = this.userSubject$.asObservable();
It says:它说:
Member userChanged$ should be declared before all private instance field definitions.eslint@typescript-eslint/member-ordering
成员 userChanged$ 应该在所有私有实例字段定义之前声明。eslint@typescript-eslint/member-ordering
I like this rule.我喜欢这个规则。 But how can I use the above code without disabling this rule?
但是如何在不禁用此规则的情况下使用上述代码?
If I'll change the order then it says:如果我要更改订单,那么它会说:
Property 'userSubject$' is used before its initialization.
属性“userSubject$”在其初始化之前使用。
You can move the initialization into the constructor:您可以将初始化移动到构造函数中:
userChanged$: Observable<UserModel>;
private userSubject$: BehaviorSubject<UserModel>;
constructor() {
this.userSubject$ = new BehaviorSubject<UserModel>(null);
this.userChanged$ = this.userSubject$.asObservable();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.