我有一个简单的按钮和一个指令,我想访问该按钮的样式,在指令中使用onclick()函数添加MarginLeft,该指令不起作用,但是从构造函数设置css时,如何在单击时使用它呢?请帮忙:
指令:
import { Directive, ElementRef } from '@angular/core';
@Directive({
selector: '[Bluecolored]'
})
export class BluecoloredDirective {
constructor(private element:ElementRef) {
console.log(element);
element.nativeElement.style.color="blue";
}
clicked(){
this.element.nativeElement.style.marginLeft=20;
console.log("marzi"+this.element.nativeElement.style.marginLeft);
}
}
Run Code Online (Sandbox Code Playgroud)
这是模板:
<p Bluecolored>
new-fom works!
</p>
<h1 Bluecolored>Blue Colored</h1>
<button (click)="clicked()" Bluecolored>Click</button>
Run Code Online (Sandbox Code Playgroud) 我有 Angular 的背景。从 vue 开始对我来说是一次不错的经历,直到我遇到了一个 VueJS 开发人员似乎已经在上面拉屎并躲在地毯下的问题。 我们如何创建一个表单,用户可以在输入字段中按 Enter 来提交表单
这真是令人失望。
如果您知道答案,请也将其发布在官方 vue 文档中。
*注意:我的解决方法:我v-on:keydown.enter.prevent='loginUser'
在每个输入字段上使用。有什么方法可以不以这种方式使用它(在每个输入字段上)。