Skip to content

Breaking changes in 2.1.4 with NG2.1 #12727

Closed
@brachi-wernick

Description

@brachi-wernick

TypeScript Version: 2.1.4 with ng 2.1.x

Code1 failed:

    private _value:string;
  
  set value(value: string) {
            this._value = value;
      }

@Input()
   get value() {
        return this._value;
    }

Code2 failed:

    private _value:string;

  get value() {
        return this._value;
    }

  @Input()
    set value(value: string) {
            this._value = value;
      }

Expected behavior:
should work as before upgrade, I can use the value as input in html.
@input can be above a get method or above a set method. and get/set method can appear in the class in each place.

Actual behavior:
get an error: Can't bind to 'value' since it isn't a known property of 'some-componnet'.
@input must be in the get method, but get method must appears before the set method.

this code works: but for me it is workaround:

Code1 failed:

    private _value:string;
//I change order of the get to be before the set
@Input()
   get value() {
        return this._value;
    }

    set value(value: string) {
            this._value = value;
      }

Code2 failed:

    private _value:string;
//I remove annotation from the set method and put above the get
@Input()
   get value() {
        return this._value;
    }

  
    set value(value: string) {
            this._value = value;
      }

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issueHigh Priority

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions