Ensures that a button has a valid type specified
- Type: suggestion
The rule does not have any configuration options.
The following examples are generated automatically from the actual unit tests within the plugin, so you can be assured that their behavior is accurate based on the current commit.
❌ - Toggle examples of incorrect code for this rule
{
"rules": {
"@angular-eslint/template/button-has-type": [
"error"
]
}
}
<button></button>
~~~~~~~~~~~~~~~~~
{
"rules": {
"@angular-eslint/template/button-has-type": [
"error"
]
}
}
<button (click)="onClick()"></button>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{
"rules": {
"@angular-eslint/template/button-has-type": [
"error"
]
}
}
<button type="whatever"></button>
~~~~~~~~~~~~~~~
{
"rules": {
"@angular-eslint/template/button-has-type": [
"error"
]
}
}
<button [attr.type]="'whatever'"></button>
~~~~~~~~~~~~~~~~~~~~~~~~
✅ - Toggle examples of correct code for this rule
{
"rules": {
"@angular-eslint/template/button-has-type": [
"error"
]
}
}
<button [attr.type]="'button'"></button>
{
"rules": {
"@angular-eslint/template/button-has-type": [
"error"
]
}
}
<button [attr.type]="'submit'"></button>
{
"rules": {
"@angular-eslint/template/button-has-type": [
"error"
]
}
}
<button [attr.type]="'reset'"></button>
{
"rules": {
"@angular-eslint/template/button-has-type": [
"error"
]
}
}
<button type="button"></button>
{
"rules": {
"@angular-eslint/template/button-has-type": [
"error"
]
}
}
<button type="submit"></button>
{
"rules": {
"@angular-eslint/template/button-has-type": [
"error"
]
}
}
<button type="reset"></button>
{
"rules": {
"@angular-eslint/template/button-has-type": [
"error"
]
}
}
<button class="primary" type="submit"></button>
{
"rules": {
"@angular-eslint/template/button-has-type": [
"error"
]
}
}
<button (click)="onClick()" type="button"></button>
{
"rules": {
"@angular-eslint/template/button-has-type": [
"error"
]
}
}
<button [class.primary]="true" [attr.type]="'submit'"></button>
{
"rules": {
"@angular-eslint/template/button-has-type": [
"error"
]
}
}
<button [disabled]="true" [attr.type]="'button'"></button>