📅  最后修改于: 2023-12-03 15:35:10.525000             🧑  作者: Mango
The styleUrls
property is an array of URLs for stylesheets to use with an Angular component.
When an Angular component is created, it can have styles that are unique to that component. The styleUrls
property allows developers to add external stylesheets to their components without having to embed the styles in the component's TypeScript code.
When the component is rendered, the stylesheets specified in styleUrls
are loaded into the browser and applied to the component. This allows developers to keep their components modular and reusable, as they can simply reuse the same stylesheets across multiple components.
Here's an example of how to use styleUrls
in an Angular component:
import { Component } from '@angular/core';
@Component({
selector: 'app-example-component',
templateUrl: './example.component.html',
styleUrls: ['./example.component.scss']
})
export class ExampleComponent {}
In this example, the styleUrls
property is set to an array containing the URL of an external stylesheet (example.component.scss
). This stylesheet will be loaded and applied to the component when it is rendered.
The styleUrls
property of an Angular component is a powerful feature that allows developers to create modular, reusable components with unique styles. By externalizing styles into separate stylesheets, developers can keep their code clean and maintainable, while still having complete control over the styles used in their components.