Thursday, March 23, 2017

Default and OnPush are the two varieties of ChangeDetectionStrategy.

The OnPush approach will turn off all of the watchers and your data will only update when an input change.

@Component({
   template: `
      <h2>{{vData.name}}</h2>
      <span>{{vData.email}}</span>
   `,
   changeDetection: ChangeDetectionStrategy.OnPush
})
class VCardCamp {
   @Input() vData;
}

 
 

More about the above:

  1. template in an Angular 2 component may be replaced with templateUrl to reference an .html file
  2. The backtick thing above for string formating is real. It's the key above Tab, not the key left of the Enter. Use single curly braces and a leading dollar sign for this sort of formatting in TypeScript standalone:
    let foo: number;
    foo = 13;
    let bar: string;
    bar = `A baker's dozen has ${foo} donuts in it!`
    alert(bar);

No comments:

Post a Comment