parent
							
								
									8945d7c7c1
								
							
						
					
					
						commit
						72db3e8d54
					
				| @ -0,0 +1,14 @@ | |||||||
|  | @Component({ | ||||||
|  |   selector: 'app-nav-bar', | ||||||
|  |   template: ` | ||||||
|  | <nav [style]='navStyle'> | ||||||
|  |   <a [style.text-decoration]="activeLinkStyle">Home Page</a> | ||||||
|  |   <a [style.text-decoration]="linkStyle">Login</a> | ||||||
|  | </nav>` | ||||||
|  | }) | ||||||
|  | export class NavBarComponent { | ||||||
|  |   navStyle = 'font-size: 1.2rem; color: cornflowerblue;'; | ||||||
|  |   linkStyle = 'underline'; | ||||||
|  |   activeLinkStyle = 'overline'; | ||||||
|  |   /* . . . */ | ||||||
|  | } | ||||||
| @ -174,6 +174,12 @@ Optionally, you can add a unit extension like `em` or `%`, which requires a numb | |||||||
| You can write a style property name in either [dash-case](guide/glossary#dash-case), or | You can write a style property name in either [dash-case](guide/glossary#dash-case), or | ||||||
| [camelCase](guide/glossary#camelcase). | [camelCase](guide/glossary#camelcase). | ||||||
| 
 | 
 | ||||||
|  | <code-example language="html"> | ||||||
|  |   <nav [style.background-color]="expression"></nav> | ||||||
|  | 
 | ||||||
|  |   <nav [style.backgroundColor]="expression"></nav> | ||||||
|  | </code-example> | ||||||
|  | 
 | ||||||
| </div> | </div> | ||||||
| 
 | 
 | ||||||
| ### Binding to multiple styles | ### Binding to multiple styles | ||||||
| @ -181,8 +187,8 @@ You can write a style property name in either [dash-case](guide/glossary#dash-ca | |||||||
| To toggle multiple styles, bind to the `[style]` attribute—for example, `[style]="styleExpression"`. | To toggle multiple styles, bind to the `[style]` attribute—for example, `[style]="styleExpression"`. | ||||||
| The `styleExpression` can be one of: | The `styleExpression` can be one of: | ||||||
| 
 | 
 | ||||||
| * A string list of styles such as `"width: 100px; height: 100px;"`. | * A string list of styles such as `"width: 100px; height: 100px; background-color: cornflowerblue;"`. | ||||||
| * An object with style names as the keys and style values as the values, such as `{width: '100px', height: '100px'}`. | * An object with style names as the keys and style values as the values, such as `{width: '100px', height: '100px', backgroundColor: 'cornflowerblue'}`. | ||||||
| 
 | 
 | ||||||
| Note that binding an array to `[style]` is not supported. | Note that binding an array to `[style]` is not supported. | ||||||
| 
 | 
 | ||||||
| @ -193,6 +199,11 @@ Updating the property without changing object identity has no effect. | |||||||
| 
 | 
 | ||||||
| </div> | </div> | ||||||
| 
 | 
 | ||||||
|  | #### Single and multiple-style binding example | ||||||
|  | 
 | ||||||
|  | <code-example path="attribute-binding/src/app/single-and-multiple-style-binding.component.ts" header="nav-bar.component.ts"> | ||||||
|  | </code-example> | ||||||
|  | 
 | ||||||
| If there are multiple bindings to the same style attribute, Angular uses [styling precedence](guide/style-precedence) to determine which binding to use. | If there are multiple bindings to the same style attribute, Angular uses [styling precedence](guide/style-precedence) to determine which binding to use. | ||||||
| 
 | 
 | ||||||
| The following table summarizes style binding syntax. | The following table summarizes style binding syntax. | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user