[英]Angular - Disable Button
<div id="home-container">
<div class="sidebar">
<button mat-raised-button [disabled]="true">This is a button</button>
</div>
<div class="main-panel">
<ac-map></ac-map>
</div>
</div>
环境:
嗨,大家好,
在显示我的 angular 项目时,我遇到了一些不良行为。 上面的示例显示了一个简单的组件,其中包含一个默认禁用的按钮(我使用 'true' 作为变量的占位符)。 当我加载组件时,按钮应该被禁用。 然而。 加载组件时,按钮在前一秒或两秒内启用,然后被禁用 - 使其看起来杂乱无章。 我怎样才能避免这种情况?
亲切的问候,斯科特。
根据您的要求,我建议您阅读有关 Angular 组件生命周期的文档。 https://angular.io/guide/lifecycle-hooks
请查看此内容以获取实时样本。
import { Component, OnInit } from "@angular/core";
/**
* @title Basic buttons
*/
@Component({
selector: "button-overview-example",
templateUrl: "button-overview-example.html",
styleUrls: ["button-overview-example.css"]
})
export class ButtonOverviewExample implements OnInit {
disabled = true;
toggle() {
this.disabled = !this.disabled;
}
ngOnInit(): void {
this.disabled = false;
}
}
在此示例中,我使用变量disabled
来指示按钮 state,并实现了OnInit
挂钩,我将其更改为false
为true
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.