Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

How to subscribe changes to property of a directive

<input [myDirective]="myService.parameter" myServiceValue="{{myService.value}}" ... >


@Directive({
  selector: '[myDirective]'
})
export class parameterDirective implements OnInit, OnChanges {
  @Input('myDirective') parameter: parameter;
  @Input() myServiceValue: string;

  constructor(private el: ElementRef, private renderer: Renderer) {
  }

  ngOnInit(): void {
  }

  ngOnChanges(changes: SimpleChanges): void {
    switch (this.parameter) {
      case parameter.EnumValue:
        this.renderer.setElementClass(this.el.nativeElement, "my-class", changes.myServiceValue.currentValue > 100);
        break;
      default:
    }

  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: sort string array object javascript 
Javascript :: canvas circle blurry 
Javascript :: add position suffix to number in js 
Javascript :: remove or add class jquery 
Javascript :: how to load a javascript game from react 
Javascript :: In JavaScript, all numbers are stored in the format float64 
Javascript :: Using anonymous functions as arguments of other functions 
Javascript :: sequelize read from moel 
Javascript :: javascript map shorthand 
Javascript :: regression to the mean using javascript 
Javascript :: JavaScript object numeric keys 
Javascript :: angularjs component stackoverflow 
Javascript :: example of post increment in js 
Javascript :: react native bottom bar curved 
Javascript :: react native star rating component 
Javascript :: js to jquery converter online 
Javascript :: usescript +react 
Javascript :: sequlize where clause involving associated relationship 
Javascript :: Pausing setInterval when page/ browser is out of focus 
Javascript :: export data from paginated api javascript vuetify 
Javascript :: nestjs openapi yaml file 
Javascript :: rename data table button 
Javascript :: vite esbuild configuration 
Javascript :: javascript llenar array con objetos 
Javascript :: express plus es6 
Javascript :: put validation on the cell number in angular 
Javascript :: express static page 
Javascript :: how to trigger a function after stop writing in input text jquery event 
Javascript :: react native navigation export 
Javascript :: email validation in form using javascript 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =