How to set default values for Angular 2 component properties? Last Updated : 19 Aug, 2020 Comments Improve Suggest changes Like Article Like Report In Angular 2, we can pass the value of a variable between two components (from parent to child) using the Input Decorator. Using these Input decorators we can also set the default values of the properties. Below I had detailly elaborated in a comprehensive way on how to set default values for Angular 2 component. Syntax: @Input() PropertyName = Default Value /* @Input country = 'India' */ Approach: First code the .html file with respect to requirements. Then include the default property in the child component. Now initialize the property with a default value using the @Input() decorator. We should also import the Input decorator from '@angular/core'. Once initialization is completed, use the property in HTML file to display in the browser. Syntax for importing: import { Input } from '@angular/core'; Implementation by code: app.component.html: html <p>Welcome to GeeksforGeeks </p> <app-child [country] = "countryName"></app-child> app.component.ts: javascript import { Component } from '@angular/core'; @Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: [ './app.component.css' ] }) export class AppComponent { constructor() { } ngOnInit() {} countryName = 'India'; } child.component.ts: javascript import { Component, Input, OnInit} from '@angular/core'; @Component({ selector: 'app-child', templateUrl: './child.component.html' }) export class ChildComponent implements OnInit { constructor() { } ngOnInit() {} @Input() country = 'Australia'; @Input() capital = 'New Delhi'; } child.component.html: html <p> Country is : {{country}} </p> <p> Capital is : {{capital}} </p> Conclusion:As we are passing country property as 'India', it will be displayed. But when it comes to capital as we are not passing any value it displays the default value in child.component.ts file. Output: Comment More infoAdvertise with us Next Article How to set default values for Angular 2 component properties? B bunnyram19 Follow Improve Article Tags : Web Technologies AngularJS AngularJS-Misc Similar Reads Angular PrimeNG Form Editor Default Component Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use the Form Editor Default Component in Angular PrimeNG. We will a 3 min read How to pass data from Parent to Child component in Angular ? We can use the @Input directive for passing the data from the Parent to Child component in AngularUsing Input Binding: @Input - We can use this directive inside the child component to access the data sent by the parent component. Here app.component is the Parent component and cdetail.component is th 2 min read Angular PrimeNG Form SelectButton Value Binding Component Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. In this article, we will know how to use the Form SelectButton Value Binding Component in Angular Pr 3 min read Angular PrimeNG Form RadioButton Properties Component Angular PrimeNG is a UI component library for Angular Applications. It offers many pre-built themes and UI components for a variety of tasks like inputs, menus, charts, Buttons, etc. This article will discuss the Angular PrimeNG Form RadioButton Properties Component. The PrimeNG Form Component is bu 4 min read Angular PrimeNG Form Dropdown Properties Component Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use the Form Dropdown Properties Component in Angular PrimeNG. The 7 min read Angular PrimeNG Form Knob Properties Component Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. In this article, we will know how to use the InputNumber component in Angular PrimeNG. We will also 4 min read How to pass string to a component using Angular2 ? In angular2, a component is considered as a 'view' with its own logic and data. Data binding is the process of combining data values with their corresponding representations. For components, string values can be passed, either directly as string literals or by storing the string literal in a variabl 4 min read Angular PrimeNG Table ColumnFilter Properties Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. It provides a lot of templates, components, theme design, an extensive icon library, and much more. 8 min read Angular PrimeNG Form Listbox Properties Component Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. In this article, we will see how to use the Form Listbox Properties Component in Angular PrimeNG. Th 6 min read Angular PrimeNG Form MultiSelect Properties Component Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. In this article, we will know how to use the Dropdown component in Angular Angular PrimeNG Form Mult 7 min read Like