上次更新后的VSCode现在知道如何自动添加导入.然而,它添加使用相对路径 - 任何想法,如果它是以某种方式可配置?
可以这样做吗?(因为我试过,但没有成功):
@Injectable()
class A {
constructor(private http: Http){ // <-- Injection in root class
}
foo(){
this.http.get()...
};
}
@Injectable()
class B extends A{
bar() {
this.foo();
}
}Run Code Online (Sandbox Code Playgroud)
我正在尝试创建自定义验证器@Directive,问题是在构造函数中我只能访问ElementRef object,但是我需要一些方法NgControl。
@Directive({
selector: "[my-directive][ngModel]",
providers: [some providers here]
})
export class MyValidator extends RootValidator {
constructor(el: ElementRef, public renderer: Renderer) {
super(el, renderer);
// TODO: Here i need access to ngControl instead of ElementRef
errorsFromServerEmitter.subscribe(next => {
// ... some useful code here and then
ngControl.updateValueAndValidity();
})
}
validate(c: FormControl) {
// ... some validations
return errors;
}
Run Code Online (Sandbox Code Playgroud)
我需要以某种方式对服务器的响应做出反应。在这个响应中,我收到“ extended”错误,这些错误了解数据库一致性和其他一些内容......
例如
enum ABC { A = "a", B = "bb", C = "ccc" };
alert("B" in ABC); // true
alert("bb" in ABC); // false (i wanna true)
Run Code Online (Sandbox Code Playgroud)
请记住,我们讨论字符串枚举功能.
为什么不可能做这样的事情:
var stringArray: string[] = ["a", "b", "c"];
stringArray.map(str: string => console.log(str));
Run Code Online (Sandbox Code Playgroud) typescript ×4
angular ×2
enums ×1
inject ×1
injectable ×1
lambda ×1
parameters ×1
validation ×1