File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ # Angular Material bi-directionality
2+
3+ ### Setting a text-direction for your application
4+ The [ ` dir ` attribute] ( https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/dir )
5+ is typically applied to ` <html> ` or ` <body> ` element of a page. However, it can be used on any
6+ element to apply a text-direction to a smaller subset of the page.
7+
8+ All Angular Material components automatically reflect the LTR/RTL direction
9+ of their container.
10+
11+ ### Reading the text-direction in your own components
12+ ` @angular/cdk ` provides a ` Directionality ` injectable that can be used by any component
13+ in your application. To consume this injectable, you must import ` BidiModule `
14+ from ` @angular/cdk ` .
15+
16+ ` Directionality ` provides two useful properties:
17+ * ` value ` : the current text direction, either ` 'ltr' ` or ` 'rtl' ` .
18+ * ` change ` : an ` Observable ` that emits whenever the text-direction changes. Note that this only
19+ captures changes from ` dir ` attributes _ inside the Angular application context_ . It will not
20+ emit for changes to ` dir ` on ` <html> ` and ` <body> ` , as these are assumed to be static.
21+
22+ #### Example
23+ ``` ts
24+ @Component ({ /* ... */ })
25+ export class MyCustomComponent {
26+ private dir: Direction ;
27+
28+ constructor (directionality : Directionality ) {
29+ this .dir = directionality .value ;
30+ directionality .change .subscribe (() => {
31+ this .dir = directionality .value ;
32+ });
33+ }
34+ }
35+ ```
You can’t perform that action at this time.
0 commit comments