简体   繁体   English

具有属性选择器的组件上的主机绑定不起作用

[英]Hostbinding on component with attribute selector not working

The goal: I want to customize a component attribute from within a directive using @Hostbinding .目标:我想使用@Hostbinding从指令中自定义组件属性。 The attribute name is disabled .属性名称已禁用

The problem: I'm getting this error:问题:我收到此错误:

Can't bind to 'disabled' since it isn't a known property of 'sd-form'.\n1.无法绑定到“已禁用”,因为它不是“sd-form”的已知属性。\n1。 If 'sd-form' is an Angular component and it has 'disabled' input, then verify that it is part of this module.\n2.如果“sd-form”是一个 Angular 组件并且它具有“禁用”输入,则验证它是否是该模块的一部分。\n2. If 'sd-form' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.\n3.如果“sd-form”是一个 Web 组件,则将“CUSTOM_ELEMENTS_SCHEMA”添加到此组件的“@NgModule.schemas”以抑制此消息。\n3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component.要允许任何属性,请将“NO_ERRORS_SCHEMA”添加到此组件的“@NgModule.schemas”。 recognized, yet it's part of the component on which the directive is used.已识别,但它是使用该指令的组件的一部分。

This is my directive这是我的指令

@Directive({
  selector: '[sixDisableNotAutorized]'
})
export class NotAutorizedDisableDirective extends RxjsComponent implements AfterViewChecked {

  @Input('sixDisableNotAutorized')
  autority: AuthorityEnum;

  @HostBinding('disabled')
  disabledState: boolean;
  ...
}

this is my component:这是我的组件:

@Component({
  selector: 'sd-form[radio-group], sd-form[radio-group-inline]',
  templateUrl: './form-radio-group.component.html',
  styleUrls: [
    './form-radio-group.component.scss',
  ],
  encapsulation: ViewEncapsulation.None
})
export class SdFormRadioGroupComponent extends CustomValueAccessorComponent<ISdFormComponentItem> implements ControlValueAccessor {

  currentValue: ISdFormComponentItem;

  @HostBinding('class.six__is-disabled')
  @Input()
  disabled = false;

  ...
}

this is the dom:这是 dom:

<sd-form radio-group
         formControlName="myForm"
         idField="myForm"
         nameField="myForm"
         [sixDisableNotAutorized]="'EDITION_BI_CHANTIER'">
</sd-form>

change @HostBinding('disabled') to @HostBinding('attr.disabled')@HostBinding('disabled')更改为@HostBinding('attr.disabled')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM