【问题标题】:Can't bind to 'disabled' since it isn't a known property of '<button>'无法绑定到“禁用”,因为它不是“<button>”的已知属性
【发布时间】:2017-07-08 14:55:01
【问题描述】:

我刚开始学习 Angular,但出现以下错误: 无法绑定到“禁用”,因为它不是&lt;button&gt; 的已知属性。 在互联网上搜索我刚刚发现了类似的错误,但它们与未导入 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 中使用小写字母,如&lt;button [disabled]="!Button"&gt;Click me&lt;/button&gt;
  • 您不能将“已禁用”大写。它必须被“禁用”。
  • 谢谢@Maximus!这就是问题所在,我不敢相信我正试图找到问题,而且它是如此简单:(

标签: javascript angular


【解决方案1】:

试试这个

 <button [disabled]="!Button">Click me</button>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-05
    • 2017-06-21
    • 2017-02-03
    • 2017-10-20
    • 1970-01-01
    • 1970-01-01
    • 2019-10-10
    • 1970-01-01
    相关资源
    最近更新 更多