在寻找有关 angular 文件夹结构的良好实践时,我偶然发现了这段代码:
内容布局.component.html:
<div [class]="theme">
<div class="mat-app-background">
<app-nav></app-nav>
<div class="container">
<router-outlet></router-outlet>
</div>
<app-footer></app-footer>
</div>
</div>
据我了解,该class
标签用于将此组件 HTML 与 CSS 类绑定。但是方括号引起了我的注意,css 绑定的 [class] 和 class 之间有什么真正的区别吗?我无法自己搜索正确的搜索词/功能名称
括号[]
表示该值是您组件中的一个属性,因此它不会说将类theme
应用于元素,而是会theme
在您的组件中查找一个属性并使用存储在其中的任何内容。
class="theme" // apply class theme
// Component
public theme = 'theme';
// HTML
[class]="theme" // use what's stored in property "theme"
or
[class]="'theme'" // use string 'theme'
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句