Kendo UI for Angular:无法绑定到 'primary',因为它不是 'button' 的已知 属性

Kendo UI for Angular: Can't bind to 'primary' since it isn't a known property of 'button'

我收到此错误消息:

Can't bind to 'primary' since it isn't a known property of 'button'.

我正在使用 yo aspnetcore-spa angular 生成器。 BrowserAnimationsModuleButtonsModule 在我的 app.module 中导入并在导入中注册。我所有的 angular 和 kendo 软件包都是最新版本。

此外,当我从 <button> 中删除 [primary]="true" 时,错误消失了。之后,我再次添加 [primary]="true" 并且(不刷新页面,HMR 重建)它工作正常。再一次,如果我刷新页面,错误再次出现。

有什么解决办法吗?

提前致谢。

您的按钮应如下所示:

<button kendoButton [primary]="true">Primary</button>

不要忘记'kendoButton'。

Primary 不需要括号,尽管他们的例子说需要。尝试:

<button kendoButton primary="true">Primary</button>

确保您在模块中导入 ButtonsModule

import { ButtonsModule } from '@progress/kendo-angular-buttons';

@NgModule({
  declarations: [ButtonComponent],
  imports: [ButtonsModule],
  exports: [ButtonComponent]
})

这是我的测试结果

A) [初级]="true"

<button kendoButton (click)="onButtonClick()" [primary]="true">My Kendo UI Angular Button</button>

包含cssclassk-primary 不包含primary属性

<button _ngcontent-ogg-c2="" kendobutton="" ng-reflect-primary="true" class="k-button k-primary" dir="ltr">My Kendo UI Angular Button</button>

B) 初级="true"

<button kendoButton (click)="onButtonClick()" primary="true">My Kendo UI Angular Button</button>

包括cssclassk-primary和primary属性

<button _ngcontent-jow-c2="" kendobutton="" primary="true" ng-reflect-primary="true" class="k-button k-primary" dir="ltr">My Kendo UI Angular Button</button>

C) [初级]="false"

<button kendoButton (click)="onButtonClick()" [primary]="false">My Kendo UI Angular Button</button>

不包括 css class k-primary 并且不包括主要属性

<button _ngcontent-oto-c2="" kendobutton="" ng-reflect-primary="false" class="k-button" dir="ltr">My Kendo UI Angular Button</button>

D) 主=假

<button kendoButton (click)="onButtonClick()" primary="false">My Kendo UI Angular Button</button>

包括cssclassk-primary和primary属性

<button _ngcontent-ktx-c2="" kendobutton="" primary="false" ng-reflect-primary="false" class="k-button k-primary" dir="ltr">My Kendo UI Angular Button</button>

结论

  1. 括号中的主要是正确的语法。这意味着 属性 绑定,即允许您设置视图元素 (reference). The reason why removing bracket works for some people because modem Web browser will ignore attribute that it does not recognize. (reference)
  2. 的 属性 的单向机制
  3. 错误Can't bind to 'primary' since it isn't a known property of 'button' 是由于Kendo UI 模块没有正确导入。 (reference)