【发布时间】:2017-07-08 14:55:01
【问题描述】:
我刚开始学习 Angular,但出现以下错误:
无法绑定到“禁用”,因为它不是<button> 的已知属性。
在互联网上搜索我刚刚发现了类似的错误,但它们与未导入 FormsModule 的事实有关,这似乎不是我的情况。
app.components.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app';
Button = false;
}
app.component.html
<div style="text-align:center">
<h1>
Welcome to {{title}}!!
</h1>
<button [Disabled]="!Button">Click me</button>
</div>
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserModule,
FormsModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
【问题讨论】:
-
在
Disabled中使用小写字母,如<button [disabled]="!Button">Click me</button> -
您不能将“已禁用”大写。它必须被“禁用”。
-
谢谢@Maximus!这就是问题所在,我不敢相信我正试图找到问题,而且它是如此简单:(
标签: javascript angular