Components, Bootstrap, and the DOM - lordoftheflies/angular-essential-training GitHub Wiki

Selecting transcript lines in this section will navigate to timestamp in the video

  • [Narrator] Angular is built upon components. The starting point of an angular app is the bootstrapping of the initial parent component. Much like the HTML DOM tree that starts with an HTML element and then branches down from there. Angular runs on a component tree model. After the Angular loads the first component with the bootstrap call it then looks within that component's HTML view and sees if it has any nested components. If so, Angular finds matches and runs the appropriate component code on those. This repeats for each component down the tree. A component in Angular is used to render a portion of HTML and provide functionality to that portion. It does this through a component class in which you can define application logic for the component. For example, you can have a media item component that can have a property named mediaItem that represents the data for a media item. And that component can also have a method called onDeleteClick that could handle raising the delete media item event. With each component in angular you can specify an HTML template. The markup that will get rendered. And through the use of the component class and how Angular renders the component, You can display the data for the media item property in your template. And Angular provides an easy syntax known as the template syntax to wire up to DOM events within your template. So you can wire up the click event on a button to the onDeleteClick method. You can even use components within components. This is where the component tree comes into play. Much like how you write HTML creating nested elements within elements, you can build out your Angular apps by having components rendering components within their templates. Each component gets configured with a selector which tells Angular what markup element tag to associate the component class logic with. When you build a component in Angular, you are creating support for a new custom element for the DOM.