Components in Angular - Learning Angular (Part 3) — Transcript
Full transcript
- 0:02hey friends welcome back an angular the
- 0:06core part of any application is the use
- 0:08of components components in angular have
- 0:11three parts the component class written
- 0:14in typescript provides developers a
- 0:16place to build their application logic
- 0:19consider this to be the place where one
- 0:22may make API calls for data or Define
- 0:25event handlers for example a component
- 0:28also has an HTML template the template
- 0:31is where we Define the user interface
- 0:33for the component
- 0:35we can write this in at the component
- 0:37class if it's a small template or for
- 0:40more complex templates we can include
- 0:41them in their own HTML file the final
- 0:45part of the component are the Styles the
- 0:48angular CLI supports authoring styles
- 0:50with SAS less or plain CSS the Styles we
- 0:54write for our components are scoped to
- 0:57our components
- 0:58similar to the component template
- 1:00component Styles can be included in line
- 1:03within the component class or written in
- 1:06their own separate file
- 1:08in this course we'll keep the Styles in
- 1:11a separate file
- 1:13now let's take what we've just learned
- 1:15about components and apply it to our
- 1:18application this application can be
- 1:20built up from multiple components first
- 1:24there's the header with the homes Dash
- 1:26app logo that will appear on all of the
- 1:29pages now we don't need to make this a
- 1:32component we can add it to the app
- 1:34component template and just leave it
- 1:36there next there's a case of the search
- 1:38box and the search results
- 1:41since these two parts of the application
- 1:43are only shown together on the home page
- 1:45we're going to keep these two together
- 1:47in their own component called home
- 1:50components
- 1:51components can be nested and used inside
- 1:54one another
- 1:56now the housing locations which display
- 1:58photo name and location seem like
- 2:01another opportunity to create a
- 2:04component
- 2:05the Styles and structure will be the
- 2:07same but the data will be different
- 2:09we'll create a component for this called
- 2:11housing location component and use it in
- 2:14the home component
- 2:17if things are a little unclear about the
- 2:19approach don't worry because we'll do
- 2:21this one step at a time
- 2:23you got this
- 2:25let's get started with the header an
- 2:28app.component.ts will remove all the
- 2:31placeholder codes that we started with
- 2:33and replace it with a main tag we'll
- 2:36then add a header tag as a child with
- 2:39the class brand Dash name
- 2:43as a sibling element add an image tag
- 2:46with the class brand logo The Source the
- 2:49attribute set to the value forward slash
- 2:51assets forward slash logo.svg and we
- 2:55can't forget the alt text set that to
- 2:58logo
- 2:59since this is a logo and it is purely
- 3:02decorative we'll also add the Aria
- 3:04hidden attribute and set the value to
- 3:06true
- 3:08saving app Dot component.ts and
- 3:10reviewing the content in the browser
- 3:12will reveal our logo but the Styles have
- 3:15not been applied just yet we'll get
- 3:18there
- 3:19let's move on to the home component that
- 3:21we discussed that will contain the
- 3:23search bar and the search results
- 3:25to create a component we'll run the
- 3:28following command from the command line
- 3:29of our project
- 3:31NG generate component home dash dash
- 3:36Standalone dash dash inline Dash
- 3:39template
- 3:40energy generate component will instruct
- 3:43the angular CLI to create a component
- 3:46Force followed by the home which is the
- 3:49name of our component next we include
- 3:52some configuration by specifying Flags
- 3:54we include dash dash Standalone to make
- 3:57it a standalone component Standalone
- 3:59components are angular's new component
- 4:01style that reduce complexity and add
- 4:04some other cool features
- 4:06because the template code is going to be
- 4:08minimal will also include dash dash
- 4:11inline Dash template
- 4:14this results in less files for us to
- 4:17manage
- 4:18since we aren't focusing on the Styles
- 4:20in this course we'll keep the Styles in
- 4:22a separate file
- 4:25let's run this command to create our new
- 4:27component
- 4:28the output of the command confirms which
- 4:31files have been created and where they
- 4:33are located in the project
- 4:35let's update
- 4:37app.component.ts to reference our new
- 4:39component in the template
- 4:42first we'll add a section element as a
- 4:44sibling to the header element
- 4:46we'll give the section element the class
- 4:48content as a child of the section
- 4:51element let's add our component app dash
- 4:55home
- 4:56our components use the app dash prefix
- 4:58this can be configured in your
- 5:00application if this is something that
- 5:02you'd like to change for us this is fine
- 5:05and let's save the changes and review
- 5:07the updates in the browser
- 5:09the code editor may have an error here
- 5:11that's because the main application
- 5:13component app component needs to know
- 5:16about our new home component to fix this
- 5:19issue we'll add a new property to the
- 5:21component decorator metadata for app
- 5:23component called Imports the Imports
- 5:26property lets us list the dependencies
- 5:28for the component since we want to use
- 5:30home component in this template it's a
- 5:33dependency now
- 5:34first let's add a file level import for
- 5:37home component at the top of
- 5:38app.component.ts
- 5:41import home component wrapped in curly
- 5:44braces from dot forward slash home
- 5:47forward slash home dot component next in
- 5:50the component decorated metadata add a
- 5:53property called Imports set the value to
- 5:55be an array containing home component as
- 5:58the singular entry
- 6:00save all your changes then in the
- 6:03browser the render page has our header
- 6:05and the text home works great we've
- 6:09created a new component and Incorporated
- 6:11it into our application wonderful work
- 6:14you are doing great and I'm proud of you
- 6:18there are a few more steps to complete
- 6:20before we're done with this part so
- 6:21let's get back to it our next step is to
- 6:24update the template of Home component to
- 6:26contain the HTML markup for the search
- 6:29bar and results in home.component.ts
- 6:33let's add the following code to the
- 6:35template section of the component
- 6:37decorated metadata
- 6:39add a section element with a form as a
- 6:42child now the form has two children and
- 6:46input with the typeset to text and the
- 6:48placeholder attribute set to the string
- 6:50filter by City And a button with the
- 6:54type attribute set to button and the
- 6:56class set to primary
- 6:58as for the button label set it to search
- 7:02next as a sibling to the section element
- 7:05we'll add another section but this one
- 7:08will have the class results
- 7:11in just a few moments we'll add our
- 7:13housing locations to the results section
- 7:15but first let's save this and review the
- 7:18output in the browser
- 7:20fantastic we have a search and our
- 7:24button let's keep going because there's
- 7:26still more cool stuff they want to do in
- 7:27the app let's take care of the housing
- 7:30listing since we decided that it would
- 7:32be great to have a reusable component
- 7:34let's make a new one we'll run a similar
- 7:37command to the previous create component
- 7:39command from the command line in your
- 7:41project enter NG generate component
- 7:45housing location dash dash Standalone
- 7:48dash dash n line Dash template all right
- 7:52with that command run we get a new
- 7:54component in order to use this component
- 7:56we have to import it and add it as a
- 7:59dependency of the home component and
- 8:02home.component.ts add a file level
- 8:05import for a housing location component
- 8:07import housing location component
- 8:10wrapped in curly braces from dot dot
- 8:12forward slash housing Dash location
- 8:14forward slash housing Dash location dot
- 8:18component next update the Imports array
- 8:21of the component decorated metadata to
- 8:24include a reference to housing location
- 8:26components
- 8:27then in the template section of the same
- 8:30file
- 8:31add the app dash housing Dash location
- 8:33tag as a child of the results section
- 8:37elements
- 8:38save your changes and will be greeted
- 8:40with a familiar output in the browser
- 8:42the text housing location Works will be
- 8:45displayed beneath the search input and
- 8:47button
- 8:49we have one more component to update the
- 8:52housing location component we want to
- 8:54display housing locations on the screen
- 8:56but this is going to require a little
- 8:59more work so let's say what we've done
- 9:00so far and we'll pick this one up in the
- 9:03next section great work so far friends
- 9:06I'll catch you in the next section
- 9:10foreign
- 9:15[Music]
About this transcript
This page contains the full transcript of Components in Angular - Learning Angular (Part 3) by Angular, generated from the public captions YouTube serves with the video. The transcript has 1,364 words across 223 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.