Angular-da ota komponentdan ma'lumotlarni bolaga o'tkazish

Ota komponentdan ma'lumotlarni bola komponentning setter maxsus xususiyatiga o'tkazish mumkin. Keling, buni misolda ko'ramiz. Faraz qilaylik, bizda setter va getter bilan maxsus xususiyat mavjud:

app/user/user.component.tsclass UserComponent {
  private _name: string = '';
  
  set name(name: string) {
    if (name.length < 3) {
      this._name = name;
    } else {
      console.log('error');
    }
  }
  
  get age() {
    return this._userAge;
  }
}

Misol uchun, keling yosh uchun setter yarataylik, unda uzatilgan ma'lumotlarni tekshirishni amalga oshiramiz. Shuningdek, foydalanuvchi xususiyatlarini chiqarish uchun getter yaratamiz:

app/user/user.component.tsclass UserComponent {
  private _name: string = '';
  
  @Input()
  set name(name: string) {
    if (name.length > 3) {
      this._name = name;
    } else {
      console.log('error');
    }
  }
  
  get name() {
    return this._name;
  }
}

Endi ma'lumotlarni ota komponentdan bola komponentga o'tkazamiz:

app/app.component.html<user-data name="john"></user-data>

Bola komponentda esa uzatilgan ismni ekranda ko'rsatamiz:

app/user/user.component.html<p>{{ name }}</p>
Задание 1

Nima uchun _name maxsus xususiyati pastki chiziq belgisi bilan boshlanishini tushuntiring.

Задание 2

Ota komponentdan uzatiladigan mahsulot nomi va uning narxi uchun setter va getterlarni amalga oshiring.