DEV Community

Discussion on: Angular: Setters vs ngOnChanges - which one is better?

hassam7 profile image
Hassam Ali

I tend to avoid setters with the inputs if the inputs have dependency on other inputs because then the order inputs to the components matter.

class Component {
  url: Url;
  set users(users: Array<User>) {
    this._users = => {
      return user.avatar = this.url.baseUrl + user.avatar;
  private _users: Array<User>;
<component [url]="'someurl'" [users]=users /> //will work fine
<component [users]=users [url]="'someurl'" /> //will not work fine
Enter fullscreen mode Exit fullscreen mode

see this link for further details: