Deep Dive
Let’s deep dive into Angular and RxJS concepts
Components in Depth
- A component declares a reusable building block of an app
- A TypeScript class is used to define a component coupled with the
@componentdecorator
The @component decorator defines the following:
- selector:
stringvalue defining the css selector targeting an html element - inputs:
array of stringvalues defining the inputs to the component - outputs:
array of stringvalues defining the output of the component - properties:
array of stringvalues defining the properties - events:
array of stringvalues defining the events - host?: {[‘string’]: ‘string’},
- providers:
array of objects: defines the set of injectable objects that are visible to a directive/component and its light DOM children. - exportAs:
stringvalue defining the exported value - moduleId:
stringvalue defining the module id - viewProviders?:
array of objects: defines the set of injectable objects that are visible to a directive/component view DOM children. - queries: {[key: string]: any},
- changeDetection:
ChangeDetectionStrategyobject defining the strategy for detecting changes:-
ChangeDetectionStrategy.Default: sets detector mode toCheckAlways -
ChangeDetectionStrategy.OnPush: sets detector mode toCheckOnce -
ChangeDetectionStrategy.Detached: change detector sub tree is not a part of the main tree and should be skipped -
ChangeDetectionStrategy.CheckAlways: after calling detectChanges the mode of the change detector will remainCheckAlways -
ChangeDetectionStrategy.Checked: change detector should be skipped until its mode changes toCheckOnce -
ChangeDetectionStrategy.CheckOnce: after calling detectChanges the mode of the change detector will becomeChecked
-
- templateUrl:
stringvalue for the url path to the template - template:
stringvalue for the template - styleUrls:
array of stringvalues defining url paths to css files - styles:
array of stringvalues defining css styles:- styles: [‘.myclass { color: #000;}’],
- directives:
arrayof directives used in the component - pipes:
arrayof pipes used in the component - encapsulation:
ViewEncapsulationvalue that defines template and style encapsulation options:-
ViewEncapsulation.None: means do not provide any style encapsulation -
ViewEncapsulation.Emulated: No Shadow DOM but style encapsulation emulation using extra attributes on the DOM (default method) -
ViewEncapsulation.Native: means provide native shadow DOM encapsulation and styles appear in component’s template inside the shadow root.
-
TODO