Today I Learned

TIL, 2022-07-15, Angular exportAs

Understand exportAs In Angular Directive Angular

Reference

  • Template variables are defined in HTML using #. They can be used to get a reference to a component and can be used to get a reference of the variable in the directive class using ViewChild, or it can be passed to another component as an Input.
  • For directives, we can use exportAs to assign the directive to a template variable with #myTemp=myDirective.

Take Advantage of the exportAs Property in Angular

Reference

  • You use exportAs to get access to the component’s methods via a template variable.

Get reference to a directive used in a component

Reference

  • Access via constructor.
@Component({
})
export class MyComponent implements OnInit {
  constructor(private directive: MyDirective) { }

  ngOnInit(): void {
    assert.notEqual(this.directive, null); // it passes!
  }
}

5 Methods to Reduce JavaScript Bundle Size

Reference

  • Code-split with Webpack via lazy.
  • Webpack plugins for tree shaking: babel-plugin-lodash for Babel and babel-plugin-import.
  • Webpack bundle analyzer.
  • Compressing via Brotli or gzip.
  • Use production mode.

This project is maintained by daryllxd