Blog>
Snippets

One-Way Binding with Interpolation

Demonstrates how to display a component property in a template using interpolation, showcasing Angular's one-way data flow from the component to the view.
import { Component } from '@angular/core';

// Define the component
@Component({
  selector: 'app-hello-world',
  template: `<h1>Hello, {{ name }}!</h1>`
})
export class HelloWorldComponent {
  // Component property
  name: string = 'World';
}
This code snippet defines an Angular component with the selector 'app-hello-world'. It uses interpolation in its template to bind the 'name' property from the component class to the view. This is a one-way data flow example where the data is displayed in the component's template.