Tag archive: Javascript

i18nPlural pipe with number pipe – Angular

Maybe this is super obvious and not an issue which is why I couldn’t find this anywhere online. As you can see, using the number pipe before the plural pipe works fine.

// app.component.html
<p>{{ 0 | number | i18nPlural:plurals.result }}</p>     No results
<p>{{ 1 | number | i18nPlural:plurals.result }}</p>     One result
<p>{{ 100 | number | i18nPlural:plurals.result }}</p>   100 results
<p>{{ 1000 | number | i18nPlural:plurals.result }}</p>  1,000 results

// number wasn't formatted
<p>{{ 1000 | i18nPlural:plurals.result }}</p>           1000 results

// app.component.ts
export class AppComponent  {
  name = 'Angular 5';
  plurals = {
    result: {
      '=0':  'No results',
      '=1': 'One result',
      other: '# results'
    },
  };
}

Made a Stackblitz here: https://stackblitz.com/edit/number-pipe-locale-example-fng23y?file=app/app.component.html

Wrong Stuff

The issue was I couldn’t figure out how to get the number formatted with commas. Here’s some things I tried to help google index it.

{{  # | number }}
{{ resultTotal | i18nPlural:plurals.result }}
{{ resultTotal | i18nPlural:plurals.result | number }}
{{ resultTotal }} {{ resultTotal | i18nPlural:plurals.result }}

plurals = {
    result: {
      '=0':  'No results',
      '=1': 'One result',
      other: '{{count}} results',
      other: '{{# | number}} results',
      other: '# | number results'
    },
};

Tail call optimization

uncaughtException Maximum call stack size exceeded

This is specifically for nodejs RECURSIVE functions. When you know your recursive function is completing (you can use a smaller dataset and it works perfectly), and you receive a call stack size exceeded error when running a full dataset.

Upgrading Angular 1 to Angular 2 – typescript errors

The Error

/node_modules/angular2/src/core/application_ref.d.ts(38,88): error TS2304: Cannot find name 'Promise'.
/node_modules/angular2/src/core/application_ref.d.ts(92,42): error TS2304: Cannot find name 'Promise'.
/node_modules/angular2/src/core/application_ref.d.ts(151,33): error TS2304: Cannot find name 'Promise'.
/node_modules/angular2/src/core/change_detection/differs/default_keyvalue_differ.d.ts(23,15): error TS2304: Cannot find name 'Map'.
/node_modules/angular2/src/core/change_detection/differs/default_keyvalue_differ.d.ts(25,16): error TS2304: Cannot find name 'Map'.
/node_modules/angular2/src/core/di/reflective_provider.d.ts(103,123): error TS2304: Cannot find name 'Map'.
/node_modules/angular2/src/core/di/reflective_provider.d.ts(103,165): error TS2304: Cannot find name 'Map'.
/node_modules/angular2/src/core/linker/component_resolver.d.ts(8,53): error TS2304: Cannot find name 'Promise'.
/node_modules/angular2/src/core/linker/component_resolver.d.ts(12,44): error TS2304: Cannot find name 'Promise'.
/node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(59,148): error TS2304: Cannot find name 'Promise'.
/node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(100,144): error TS2304: Cannot find name 'Promise'.
/node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(105,139): error TS2304: Cannot find name 'Promise'.
/node_modules/angular2/src/core/linker/dynamic_component_loader.d.ts(106,135): error TS2304: Cannot find name 'Promise'.
/node_modules/angular2/src/facade/async.d.ts(27,33): error TS2304: Cannot find name 'Promise'.
/node_modules/angular2/src/facade/async.d.ts(28,45): error TS2304: Cannot find name 'Promise'.
/node_modules/angular2/src/facade/collection.d.ts(1,25): error TS2304: Cannot find name 'MapConstructor'.
/node_modules/angular2/src/facade/collection.d.ts(2,25): error TS2304: Cannot find name 'SetConstructor'.
/node_modules/angular2/src/facade/collection.d.ts(4,27): error TS2304: Cannot find name 'Map'.
/node_modules/angular2/src/facade/collection.d.ts(4,39): error TS2304: Cannot find name 'Map'.
/node_modules/angular2/src/facade/collection.d.ts(7,9): error TS2304: Cannot find name 'Map'.
/node_modules/angular2/src/facade/collection.d.ts(8,30): error TS2304: Cannot find name 'Map'.
/node_modules/angular2/src/facade/collection.d.ts(11,43): error TS2304: Cannot find name 'Map'.
/node_modules/angular2/src/facade/collection.d.ts(12,27): error TS2304: Cannot find name 'Map'.
/node_modules/angular2/src/facade/collection.d.ts(14,23): error TS2304: Cannot find name 'Map'.
/node_modules/angular2/src/facade/collection.d.ts(15,25): error TS2304: Cannot find name 'Map'.
/node_modules/angular2/src/facade/collection.d.ts(100,41): error TS2304: Cannot find name 'Set'.
/node_modules/angular2/src/facade/collection.d.ts(101,22): error TS2304: Cannot find name 'Set'.
/node_modules/angular2/src/facade/collection.d.ts(102,25): error TS2304: Cannot find name 'Set'.
/node_modules/angular2/src/facade/lang.d.ts(4,17): error TS2304: Cannot find name 'Map'.
/node_modules/angular2/src/facade/lang.d.ts(5,17): error TS2304: Cannot find name 'Set'.
/node_modules/angular2/src/facade/lang.d.ts(71,59): error TS2304: Cannot find name 'Map'.
/node_modules/angular2/src/facade/promise.d.ts(2,14): error TS2304: Cannot find name 'Promise'.
/node_modules/angular2/src/facade/promise.d.ts(8,32): error TS2304: Cannot find name 'Promise'.
/node_modules/angular2/src/facade/promise.d.ts(9,38): error TS2304: Cannot find name 'Promise'.
/node_modules/angular2/src/facade/promise.d.ts(10,35): error TS2304: Cannot find name 'Promise'.
/node_modules/angular2/src/facade/promise.d.ts(10,93): error TS2304: Cannot find name 'Promise'.
/node_modules/angular2/src/facade/promise.d.ts(11,34): error TS2304: Cannot find name 'Promise'.
/node_modules/angular2/src/facade/promise.d.ts(11,50): error TS2304: Cannot find name 'Promise'.
/node_modules/angular2/src/facade/promise.d.ts(12,32): error TS2304: Cannot find name 'Promise'.
/node_modules/angular2/src/facade/promise.d.ts(12,149): error TS2304: Cannot find name 'Promise'.
/node_modules/angular2/src/facade/promise.d.ts(13,43): error TS2304: Cannot find name 'Promise'.
/node_modules/rxjs/Observable.d.ts(10,66): error TS2304: Cannot find name 'Promise'.
/node_modules/rxjs/Observable.d.ts(66,60): error TS2304: Cannot find name 'Promise'.
/node_modules/rxjs/Observable.d.ts(66,70): error TS2304: Cannot find name 'Promise'.