Skip to content
This repository has been archived by the owner on Dec 4, 2017. It is now read-only.

StyleGuide - Prefer inputs over the @Attribute parameter decorator #1150

Open
johnpapa opened this issue Apr 24, 2016 · 1 comment
Open

StyleGuide - Prefer inputs over the @Attribute parameter decorator #1150

johnpapa opened this issue Apr 24, 2016 · 1 comment

Comments

@johnpapa
Copy link
Contributor

*To be discussed ... *

I copied several of these from early discussions and will list them as issues for future discussion after ngConf

cc // @mgechev @wardbell

  • Prefer inputs over the @Attribute parameter decorator.

    Why?: The input creates one-way binding which means that we can bind it to an expression and its value gets automatically updated. We can inject a property with @Attribute to a controller's constructor and get its value a single time.

    /* AVOID */
    @Component({
      selector: 'sg-button',
      template: `...`
    })
    class ButtonComponent {
      label: string;
      constructor(@Attribute('label') label) {
        this.label = label;
      }
    }
    /* RECOMMENDED */
    @Component({
      selector: 'sg-button',
      template: `...`
    })
    class ButtonComponent {
      @Input() label: string;
    }
@zoechi
Copy link

zoechi commented Apr 25, 2016

We can inject a property with @Attribute to a controller's constructor and get its value a single time.

I think this should be inject an attribute instead of inject a property. This can only be used to read statically added attributes AFAIK.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants