我是 Angular 的新手,我试图使用两个选项创建我自己的指令:
选项1:
import { Directive, ElementRef, OnInit } from '@angular/core';
@Directive({
selector: '[appBasicHighlight]'
})
export class BasicHighlightDirective implements OnInit {
constructor(private elementRef: ElementRef) {}
ngOnInit() {
this.elementRef.nativeElement.style.backgroundColor = 'green';
}
}
Run Code Online (Sandbox Code Playgroud)
选项 2:
import { Directive, ElementRef, Renderer2, OnInit } from '@angular/core';
@Directive({
selector: '[appBetterHighlight]'
})
export class BetterHighlightDirective {
constructor(private elementRef: ElementRef, private renderer: Renderer2) { }
ngOnInit() {
this.renderer.setStyle(this.elementRef.nativeElement, 'background-color', 'blue');
}
}
Run Code Online (Sandbox Code Playgroud)
教程中的讲师说它更安全,并建议使用 Renderer 而不是直接访问,但没有明确解释原因。他的意思是使用 ElementRef 直接访问 DOM,但正如您从代码中看到的,Renderer …
node.js single-page-application typescript ecmascript-6 angular
我是 Windows 用户,正在尝试连接 Heroku 中的数据库。
因此,在输入 heroku pg:psql 后,我可以访问我的数据库。
我创建了一个表,没有任何错误。所以现在我想检查我的表数据。
但跑完之后
kqhwudhkquwd=> select * from users;
'more' is not recognized as an internal or external command
Run Code Online (Sandbox Code Playgroud)
我收到这个错误。看来 SELECT 命令不起作用。请帮忙谢谢
angular ×1
ecmascript-6 ×1
heroku ×1
heroku-cli ×1
node.js ×1
postgresql ×1
psql ×1
typescript ×1