Home>Article>Web Front-end> A brief discussion on Component/Service in Angular
This article will introduce to you the Component/Service inAngular. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
css style scope, Shadow DOM
Shadow DOM is part of the HTML specification, which allows developers to encapsulate their own HTML markup, CSS styles and JavaScript. When creating a style Component, it can be enabled through settings. [Related tutorial recommendations: "angular Tutorial"]
@Component({ selector: 'my-app', template: `Hello World!
Shadow DOM Rocks! `, styles: [` :host { display: block; border: 1px solid black; } h1 { color: blue; } .red { background-color: red; } `], encapsulation: ViewEncapsulation.ShadowDom }) class MyApp { }
ViewEncapsulation Optional value:
Service (Service) acts as data Access, logical processing functions. Separate components and services to improve modularity and reusability.
Singleton service (singleton)
forRoot() mode
If multiple calling modules define providers (services) at the same time, then in multiple feature modules When this module is loaded, these services will be registered in multiple places. This results in multiple instances of the service, and the service no longer behaves like a singleton. There are several ways to prevent this:
For more programming-related knowledge, please visit:Programming Video! !
The above is the detailed content of A brief discussion on Component/Service in Angular. For more information, please follow other related articles on the PHP Chinese website!