在 true/false 语句上输入 [disabled] - Angular 2

input [disabled] on true/false statement - Angular 2

我有输入:

<input class="form-control" type="text" [(ngModel)]="context.company.city.zipCode">

弹出模式打开 2 次:当我单击 "New" 按钮时,或者当我双击网格中的公司以编辑该公司的属性时。

我的输入在 CompanyTemplatePopupComponent 中,它是在该组件启动时导入的,以防某些路径必须被定向以影响输入。

我想要的是在 this.modal.open 函数中这样写,当我打开 editCompany - 输入被禁用,当 newCompany 被激活时,输入字段也被启用。 isUpdate 已经是布尔值,如果它能以某种方式提供帮助的话。

openCompanyPopup( isUpdate, company ) {

    let companyToEdit = isUpdate ? company : this.companyTemplate;

    this.modal.open( CompanyTemplatePopupComponent, overlayConfigFactory( {
        dialogClass: 'modal-dialog style-dialog',
        company: companyToEdit,
        isUpdate: isUpdate,
        countries: this.countries,
    }, BSModalContext ) )
        .then(( d: any ) => d.result )
        .then( result => {

            if ( isUpdate ) {

                this.companyService.editCompany( result )
                    .subscribe( company => {
                        this.companyService.get().subscribe( response => this.handleSuccess( response ) );
                    } );
            }
            else {

                this.companyService.newCompany( result )
                    .subscribe( company => {
                        this.companyService.get().subscribe( response => this.handleSuccess( response ) );
                    } );
            }
        } );
}

您可以添加一个变量。在 CompanyTemplatePopupComponent.

中说布尔类型的 disableInput

以上变量可以通过模态打开后调用的函数来设置。

使用这个布尔变量来禁用或启用输入

[attr.disabled]="disableInput?'':null"

确保,如果变量设置为 false,[attr.disabled] 应设置为 null,以便在浏览器中呈现时从 HTML 中删除禁用属性。