我只是想传递一些常量给Angular Web组件。
这是我的index.html:
<body>
<cast-catalog nVisible="4" [someValue]="'ccccc'"></cast-catalog>
</body>
cast-catalog-component.ts
export class CastCatalogComponent implements OnInit {
@Input('nVisible') numVisible : number = 6;
@Input('someValue') someValue : string ;
<some other code>
我仍然得到6 numVisible而不是4和一个空白值的someValue。我没有这个问题,如果它传递数据从一个组件到另一个,但如果我做它从index.html,它不工作。
如果我们在web组件中有输入,那么当我们使用它时,命名模式就会改变。我们在Angular组件中使用了camelCase,但要从另一个HTML文件访问这个输入,我们必须使用kebab-case:所以试试这个
<cast-catalog n-visible="4" some-value="'ccccc'"></cast-catalog>
查看更多https://indepth.dev/posts/1116/angular-web-components-a-complete-guide