2018-05-29 22:17:59 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								# Reusable animations
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								#### Prerequisites
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-10-26 21:35:03 +07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								A basic understanding of the following concepts:
							 
						 
					
						
							
								
									
										
										
										
											2018-05-29 22:17:59 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								*  [Introduction to Angular animations ](guide/animations )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								*  [Transition and triggers ](guide/transition-and-triggers )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								< hr > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-05-16 20:19:47 +05:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								The [AnimationOptions ](api/animations/AnimationOptions ) interface in Angular animations enables you to create animations that you can reuse across different components.
							 
						 
					
						
							
								
									
										
										
										
											2018-05-29 22:17:59 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								## Creating reusable animations
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-05-16 20:19:47 +05:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								To create a reusable animation, use the [`animation()` ](api/animations/animation ) method to define an animation in a separate `.ts`  file and declare this animation definition as a `const`  export variable. You can then import and reuse this animation in any of your app components using the [`useAnimation()` ](api/animations/useAnimation ) API.
							 
						 
					
						
							
								
									
										
										
										
											2018-05-29 22:17:59 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-07-20 20:40:17 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								< code-example  path = "animations/src/app/animations.ts"  header = "src/app/animations.ts"  region = "reusable"  language = "typescript" > < / code-example > 
							 
						 
					
						
							
								
									
										
										
										
											2018-05-29 22:17:59 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								In the above code snippet, `transAnimation`  is made reusable by declaring it as an export variable.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								< div  class = "alert is-helpful" > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								**Note:** The `height` , `opacity` , `backgroundColor` , and `time`  inputs are replaced during runtime.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								< / div > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								You can import the reusable `transAnimation`  variable in your component class and reuse it using the `useAnimation()`  method as shown below.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2019-07-20 20:40:17 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								< code-example  path = "animations/src/app/open-close.component.3.ts"  header = "src/app/open-close.component.ts"  region = "reusable"  language = "typescript" > < / code-example > 
							 
						 
					
						
							
								
									
										
										
										
											2018-05-29 22:17:59 -07:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								## More on Angular animations
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								You may also be interested in the following:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								*  [Introduction to Angular animations ](guide/animations )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								*  [Transition and triggers ](guide/transition-and-triggers )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								*  [Complex animation Sequences ](guide/complex-animation-sequences )
							 
						 
					
						
							
								
									
										
										
										
											2019-07-20 20:40:17 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								*  [Route transition animations ](guide/route-animations )