Skip to content

Day 2 Components and Promises

Kobi Hari edited this page Mar 3, 2020 · 1 revision

Day 2 - Components and Promises

Projects:

notepad Componentization of notepad
pop-quiz-ex1 Solution of class exercise
fun-with-promises Introduction to promises in JS

Componantization of the notepad component

  • We agreed that writing full scale applications in one component is difficult to maintain, which is why angular was built to support multi-component applications
  • We created a title-presneter component that presents a title
  • We have used the @Input Decorator to add input properties that may be passed through the HTML
  • We saw the difference between passing data using [prop]="expression" syntax and prop="text" syntax. Where the first is used to bind data from the view model, and the second is used to pass a hard coded string.
  • We used the cli to auto-generate components using ng g c components/component-name. See more details Here
  • We used the @Output Directive and the EventMitter<T> class to create our own events and raise them in our components
  • We used the (event)="action()" Syntax to respond to an event in the container component
  • We used the $event keyword to access event data

Class Exercise - Components

Introduction to Promises and Async Development

  • We defined a promise as an object that tells us if an action that takes time has completed, and what is the result
  • We saw that we can not "pull" that information, but rather have to use the .then and .catch methods and provide callbacks that will be called when the promise completes
  • We saw how to create a promise using the Promise Constructor.
  • We understood what async and await keywords do and how do they affect the compilation
  • We understood that the .then method, and the async keywords, also create promises, out of other promises
  • We saw how to ue Promise.resolve to create a promise that is already completed when it is created
  • We saw how to use Promise.all and Promise.race to group promises together and wrap them in a single promise that returns all the results from all the promises or from the first one to complete.
Clone this wiki locally