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

bad ngStyle example #3072

Closed
Closed
@zoechi

Description

@zoechi

https://angular.io/docs/ts/latest/guide/template-syntax.html#!#ngStyle

setStyles() {
  let styles = {
    // CSS property names
    'font-style':  this.canSave      ? 'italic' : 'normal',  // italic
    'font-weight': !this.isUnchanged ? 'bold'   : 'normal',  // normal
    'font-size':   this.isSpecial    ? '24px'   : '8px',     // 24px
  };
  return styles;
}

should IMHO be considered as DON'T example

  • It binds a method in the view [ngClass]="setClasses()" which is discouraged and should be avoided except one knows what she's doing

  • It returns a new instance for every call. If it would at least cache the result in an instance field and return that as long as not dependencies are changed, it would be ok.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions