Why @input doesn't load the data in the variable?

Tla*_*-ES -3 typescript angular

Hello I am trying to pass info between components of the following way

Parent view

<div class="board">
    <app-ad [ad]="Title"></app-ad>
</div>
Run Code Online (Sandbox Code Playgroud)

Child component:

import { Component, OnInit, Input } from '@angular/core';

@Component({
  selector: 'app-ad',
  templateUrl: './ad.component.html',
  styleUrls: ['./ad.component.less']
})
export class AdComponent implements OnInit {

  @Input()
  ad: string;

  constructor() { console.log(this.ad) }//undefined

  ngOnInit() {console.log(this.ad) }//undefined

}
Run Code Online (Sandbox Code Playgroud)

Child view

Title: {{ad}}
Run Code Online (Sandbox Code Playgroud)

When I load the page, the variable isn't set.

Thanks

Din*_*ino 5

The problem is in your parent component, more specifically in a way how you pass the variable to [ad]. That would work fine if Title was an actual variable.

<app-ad [ad]="Title"></app-ad>
Run Code Online (Sandbox Code Playgroud)

Parent

export class ParentComponent {
  Title = 'someTitle';
}
Run Code Online (Sandbox Code Playgroud)

However if you want to pass the string value directly to template make sure to quote it

<div class="board">
    <app-ad [ad]="'Title'"></app-ad>
</div>
Run Code Online (Sandbox Code Playgroud)