Skip to content

Instantly share code, notes, and snippets.

View killerchip's full-sized avatar

Costas Ioannou killerchip

  • Morrow Digital
  • Larissa, Greece
View GitHub Profile
@killerchip
killerchip / angular-cheat-di.md
Created January 1, 2018 06:23
Angular cheatsheet: Dependency Injection

Dependency Injection

When we want to use a dependent class/value, instead of creating them ourselves, Angular's DI framework will do it for us. In order to do this, we must define for the class/value a Token. Once Angular sees that we want to inject the specific token, it will create the class/value and provide it to our class.

Injecting a Class

Create a class with Injectable decorator

@killerchip
killerchip / angular-cheatsheet-component-event-emitters.md
Last active January 1, 2018 06:49
Angular cheatsheet: Component event emitters

Component event emitters

@Output() myEvent: EventEmitter<string> = new EventEmitter();

public onClick() {
  this.myEvent.emit('you clicked me!');
}
@killerchip
killerchip / angular-tip-link-as-button.md
Created January 1, 2018 06:16
angular tip: Using a link as button
@killerchip
killerchip / angular-tip-component-class-from-inside.md
Created December 31, 2017 18:35
Angular tip: How to add a class to a component from "inside".

Component adds class to itself

When defining a component you can define a class (and other attribute) on its own host element.

For example if you define the <my-component></my-component component, you can define it to have a class like <my-component class="my-component-class"> directly from compoent code. So you are not dependent on the "user" of this component to define the class.

This can be done with the @HostBinding

export class MyComponent {
@killerchip
killerchip / angular-cheat-simple-input-no-forms.md
Created December 31, 2017 18:12
Angular cheatsheet: Simple input grabbing without formx

Simple input without complex forms

The following is a quick example of how to simply grab input from user, without using Angular forms and form builder. Of course it is for very simple cases.

HTML Template

<form>
@killerchip
killerchip / killerchip-js-toc.md
Created December 31, 2017 18:06
Javascript... coding notes, tips, cheats, guides, code snippets and tutorial articles
@killerchip
killerchip / killerchip-angular-toc.md
Last active January 21, 2018 21:02
Angular... coding notes, tips, cheats, guides, code snippets and tutorial articles
@killerchip
killerchip / angular-guide-starting-project.md
Created December 31, 2017 17:55
Angular Guide: Planning and Starting an Angular project

Starting an Angular Project Guidelines

Here follows a draft guide/checklist on how to get started with an angular project.

  • PAGE BUILDING
    • Identify and scetch Components tree.
      • Identify components and subcomponents
      • Make list of items components themselves.
    • Identify the model and model classes.
  • tip: Try to isolate data structures from components. Think... "can the component be replaced without affecting data"?
@killerchip
killerchip / killerchip-ts-toc.md
Last active April 29, 2018 04:08
Typescript... coding notes, tips, cheats, guides, code snippets and tutorial articles
@killerchip
killerchip / ts-tip-model-class-creation.md
Last active November 29, 2023 08:52
Typescript Tip: Recommended way of creating classes that model the data of your Typescript app.

Creating model classes in Typescript

Tip: Recommended way of creating classes that model the data of your Typescript app.

Creating simple classes

Create a simple class with a small set (0-3) of parameters in the constructor.

  • Define the properties directly in the parameter of the constructor.
  • Define optional parameters by defining default values