1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Angular2 @Input to a property with get/set

Discussão em 'Angular' iniciado por Paul Cavacas, Outubro 14, 2024.

  1. Paul Cavacas

    Paul Cavacas Guest

    I have an Angular2 component in that component it currently has a bunch fields that have @Input() applied before them to allow binding to that property, i.e.

    @Input() allowDay: boolean;


    What I would like to do is actually bind to a property with get/set, so that I can do some other logic in the setter, something like the following

    _allowDay: boolean;
    get allowDay(): boolean {
    return this._allowDay;
    }
    set allowDay(value: boolean) {
    this._allowDay = value;
    this.updatePeriodTypes();
    }


    how would I do this in Angular2?

    Based on Thierry Templier suggestion I changed it to, but that throws the error Can't bind to 'allowDay' since it isn't a known native property :

    //@Input() allowDay: boolean;
    _allowDay: boolean;
    get allowDay(): boolean {
    return this._allowDay;
    }
    @Input('allowDay') set allowDay(value: boolean) {
    this._allowDay = value;
    this.updatePeriodTypes();
    }

    Continue reading...

Compartilhe esta Página