What is let-* in Angular 2 templates?

ID : 20038

viewed : 12

Tags : angularangular2-templateprimengangular

Top 5 Answer for What is let-* in Angular 2 templates?

vote vote

93

update Angular 5

ngOutletContext was renamed to ngTemplateOutletContext

See also CHANGELOG.md @ angular/angular

original

Templates (<template>, or <ng-template> since 4.x) are added as embedded views and get passed a context.

With let-col the context property $implicit is made available as col within the template for bindings. With let-foo="bar" the context property bar is made available as foo.

For example if you add a template

<ng-template #myTemplate let-col let-foo="bar">   <div>{{col}}</div>   <div>{{foo}}</div> </ng-template>  <!-- render above template with a custom context --> <ng-template [ngTemplateOutlet]="myTemplate"              [ngTemplateOutletContext]="{                                            $implicit: 'some col value',                                            bar: 'some bar value'                                         }" ></ng-template> 

See also this answer and ViewContainerRef#createEmbeddedView.

*ngFor also works this way. The canonical syntax makes this more obvious

<ng-template ngFor let-item [ngForOf]="items" let-i="index" let-odd="odd">   <div>{{item}}</div> </ng-template> 

where NgFor adds the template as an embedded view to the DOM for each item of items and adds a few values (item, index, odd) to the context.

See also Using $implict to pass multiple parameters

vote vote

88

The Angular microsyntax lets you configure a directive in a compact, friendly string. The microsyntax parser translates that string into attributes on the <ng-template>. The let keyword declares a template input variable that you reference within the template.

vote vote

77

vote vote

68

Create a file, name it 1_2.data. weired idea? what you get:

  • You save up to 50% of space because you don't need to repeat the fk_to_device and fk_to_metric value for every data point.
  • You save up even more space because you don't need any indices.
  • Save pairs of (timestamp,metric_value) to the file by appending the data so you get a order by timestamp for free. (assuming that your sources don't send out of order data for a device)

=> Queries by timestamp run amazingly fast because you can use binary search to find the right place in the file to read from.

if you like it even more optimized start thinking about splitting your files like that;

  • 1_2_january2014.data
  • 1_2_february2014.data
  • 1_2_march2014.data

or use kdb+ from http://kx.com because they do all this for you:) column-oriented is what may help you.

There is a cloud-based column-oriented solution popping up, so you may want to have a look at: http://timeseries.guru

vote vote

55

If you are looking at GPL packages, RRDTool is a good one to look at. It is a good tool for storing, extracting and graphing times-series data. Your use-case looks exactly like time-series data.

Top 3 video Explaining What is let-* in Angular 2 templates?

Related QUESTION?