2 years ago

#13048

test-img

Habib01

How to use any type of property in a component on ngOnchanges

How to use any type of property in a component on ngOnchanges without @input property. I can not use Rxjs for this situation. It is not a child component so i have no @input property.
Please see the following example.

import { Component, OnInit, OnChanges, Input, TemplateRef, SimpleChanges } from '@angular/core';
@Component({
  selector: 'app-products',
  templateUrl: './products.component.html',
  styleUrls: ['./products.component.css']
})
export class ProductsComponent implements OnInit, OnChanges{  
    propertyName = "Default Text";
    constructor() { }
    
    // this.propertyName This property of value will be change any of 
    // this component 
    ngOnChanges(change:SimpleChanges){   
        console.log('ng on changes ...', change);
        // i want to fire here another Method up to change this property propertyName 
    }
  
    ngOnInit(): void {
        console.log('ng on Init ...');        
    }
}

angular

angular-changedetection

angular-lifecycle-hooks

ngonchanges

0 Answers

Your Answer

Accepted video resources