Customizing components and directives (Part 4) — Transcript
Full transcript
- 0:02hey friends welcome back so far we've
- 0:05built out the base structure of our
- 0:07application but we need a few more
- 0:10things
- 0:10one we need to build out the structure
- 0:13for the housing component
- 0:16two we need to make the component
- 0:18customizable so that we can dynamically
- 0:20create one component per housing
- 0:23location three we need to dynamically
- 0:27display the housing locations and
- 0:30finally we need to add some styling to
- 0:33the application in order to make it
- 0:35render like the screenshots
- 0:37we have some work to do so let's get to
- 0:39it let's start in the housing location
- 0:42dot component.ts file and update the
- 0:45template property of the component
- 0:47metadata with the code needed for our
- 0:49component template
- 0:51let's start by adding a section element
- 0:54with the class listing next we'll add
- 0:58three child elements
- 1:00an image tag with the class listing Dash
- 1:03photo
- 1:06an H2 tag with the class listing Dash
- 1:10heading
- 1:12and a p element with the class listing
- 1:16Dash location
- 1:17now let's save all of our changes the
- 1:20browser will be updated but we'll likely
- 1:23not find any new content and that's
- 1:25because right now the HTML doesn't have
- 1:28any content
- 1:30the content that we need are the
- 1:32specific properties that make a housing
- 1:34location unique
- 1:35let's sort that part out now
- 1:38we've created three elements in the
- 1:40template a place for the listing photo
- 1:42the listing heading text and the listing
- 1:45location it would be great to be able to
- 1:48pass data to this component that
- 1:50contained it the values that we need
- 1:51fortunately there is a feature in an
- 1:54angular that allows us to do just that
- 1:56input properties
- 1:58angular components can receive data
- 2:01through a feature called input
- 2:03properties
- 2:04now the next question is how should that
- 2:07data be configured let's review the data
- 2:11we can expect to receive that describes
- 2:13a housing location
- 2:15each location will have an ID name city
- 2:18state photo number of available units a
- 2:23Boolean value for whether or not it has
- 2:25Wi-Fi and another Boolean value for
- 2:27whether or not it has laundry
- 2:30on the landing page of the application
- 2:32will only display the name city and
- 2:35state
- 2:36these are the three properties we want
- 2:38to use in our components
- 2:41we want our component to accept housing
- 2:43location data in this specific format
- 2:45now this is a job for a type types help
- 2:49us to know what to expect from data that
- 2:52we encounter
- 2:53we can create a new type that represents
- 2:56our data we'll create an interface to
- 2:58use in our application now an interface
- 3:01is a contract between us and the data
- 3:04the interface tells us that we can
- 3:06expect the data to follow the structure
- 3:09defined by the interface we can also
- 3:12consider it to shape our data from the
- 3:15command line run NG generate interface
- 3:18housing location use a capital l for
- 3:22location
- 3:23we use the angular CLI here again with
- 3:26the generic command and we instructed to
- 3:28create an interface called housing
- 3:30location and housinglocation.ts update
- 3:34their interface to have the following
- 3:35properties that describe our data ID of
- 3:39type number
- 3:40name of type string city of type string
- 3:43state of type string photo of type
- 3:47string available units of type number
- 3:50Wi-Fi of type Boolean laundry of type
- 3:53Boolean
- 3:55save this file and we'll move on to the
- 3:57next place in the code where we'll make
- 4:00updates
- 4:01now we have the pieces to put everything
- 4:03together we'll use input properties to
- 4:06pass data into our component and use the
- 4:08interface to let the component know what
- 4:11type of data to expect
- 4:13you can Mark a component property with
- 4:14the input decorator and this tells the
- 4:16angular that the property can be set in
- 4:19a template in housing location dot
- 4:22component.ts we need to update the
- 4:24Imports to include input from angular
- 4:27forward slash core
- 4:28we also need to import housing location
- 4:31wrapped in curly braces again
- 4:34from dot dot forward slash housing
- 4:37location next in the body of housing
- 4:39location component class We'll add a new
- 4:42property called housing location
- 4:44lowercase h capital L of tight housing
- 4:48location capital h capital l
- 4:52we're going to add one more change here
- 4:54we want to prefix the housing location
- 4:57property with the input decorator to
- 5:00make it an input property
- 5:02Remember The Decorator requires the at
- 5:05symbol before The Decorator name and
- 5:07parentheses afterwards when you say this
- 5:10code the editor May display an error for
- 5:12the housing location property well
- 5:14that's because as an input we're
- 5:16expecting the value to be passed in so
- 5:19we haven't initialized it in this case
- 5:21we know that the value will be passed in
- 5:23so we'll update the property to have an
- 5:26exclamation point after the property
- 5:28name the exclamation point is called the
- 5:30non-null assertion operator and it tells
- 5:33typescript compiler that the value of
- 5:35this property won't be null or undefined
- 5:37all right now our component has an input
- 5:41property named housing location that we
- 5:43can work with and the component
- 5:45decorated metadata let's update the
- 5:47template property to access the
- 5:49properties that we need to display
- 5:51the image tag needs a source attribute
- 5:54to display an image let's add one now
- 5:57Source equal quote
- 5:59housinglocation.photo quote make sure
- 6:02that the housing location property is
- 6:04camel case
- 6:06now there's one slight change to make
- 6:08here
- 6:09as is the template treats the value of
- 6:12the source attribute as a string with
- 6:15the value housing location.photo to
- 6:18resolve that we need to use another
- 6:19feature of angular called property
- 6:21binding property binding allows us to
- 6:24tell angular that the value in quotes
- 6:26should be an actual property from the
- 6:29component class to enable property
- 6:32binding we'll wrap the source attribute
- 6:34in square brackets
- 6:36because this is an image we should be
- 6:39mindful to add an ALT text for screen
- 6:41readers and other assistive Technologies
- 6:44alt equals quote exterior photo of
- 6:48double open curly brace
- 6:51housinglocation.name double close curly
- 6:54brace okay let me explain what we just
- 6:57did the double curly braces are used for
- 6:59angular interpolation syntax we can use
- 7:02that to mix in values and expressions
- 7:04into Strings in our templates when this
- 7:07gets rendered to the screen the value
- 7:09will be a string that reads exterior
- 7:12photo of ABC or whatever the name of the
- 7:15housing location is
- 7:17we can use this all over templates it's
- 7:19a great tool to have in our toolbox so
- 7:22let's do more interpolation
- 7:25let's update the content of the H2 to be
- 7:28double open curly braces housing
- 7:31location dot name double close curly
- 7:33braces
- 7:35also update the content of the P tag to
- 7:38be double open curly braces housing
- 7:41location dot City double close curly
- 7:44braces comma space double open curly
- 7:48braces housing location dot State double
- 7:50closed curly braces we can be creative
- 7:53with interpolation to create the display
- 7:55that we want with our templates the
- 7:58housing location component now accepts
- 8:01an input that we can use to customize
- 8:03the component the next step is to work
- 8:05with the list of locations considering
- 8:08that let's add our list in
- 8:11home.component.ts let's import housing
- 8:14location from dot dot forward slash
- 8:17housing location
- 8:19then we're going to add a new property
- 8:21to the home component class called
- 8:24housing location list of type housing
- 8:27location array and we're going to assign
- 8:30it to be an empty array
- 8:32now we're going to copy and paste the
- 8:34array entries from GitHub for this
- 8:36project
- 8:37head to
- 8:39g-o-o.gle forward slash home slash app
- 8:42dash listings this URL will take you to
- 8:45code on GitHub that contains all the
- 8:46entries required in
- 8:49home.component.ts replace the empty
- 8:51array value for the housing location
- 8:53list property with the data from the
- 8:56entries you just copied
- 8:58the results section is where we want to
- 9:01iterate over the entries of the housing
- 9:03location list and display a housing
- 9:05location component for each entry in
- 9:07JavaScript whenever we want to iterate
- 9:10over an array we use something like a
- 9:11for Loop that's the same idea we want
- 9:14here we want something like a for Loop
- 9:17an angular there's a syntax we can use
- 9:19to accomplish this goal it's called the
- 9:22ng4 directive angular directives allows
- 9:26us to add additional functionality to
- 9:28elements and components
- 9:30now we're going to add the ng4 directive
- 9:33to the housing location component update
- 9:36the app dash housing Dash location tag
- 9:39to include the following asterisk ng4
- 9:42equals quotes let housing location of
- 9:46housing location list quote the code
- 9:49within the quotes is called angular
- 9:51template syntax it creates a template
- 9:54variable called housing location which
- 9:56represents an entry from the housing
- 9:58location list the next step is to pass
- 10:01the housing location data to the housing
- 10:04Dash location components using the
- 10:07inputs from the components
- 10:09update the app dash housing Dash
- 10:12location component to include
- 10:14opening square bracket housing location
- 10:17closing square bracket equals
- 10:20quote housing location quote remember
- 10:23this should be a separate attribute on
- 10:26the app dash housing Dash location
- 10:27component tag and not a part of the ng4
- 10:33save your progress and check the browser
- 10:36we have data being displayed this is
- 10:39fantastic progress so far but I'm sure
- 10:41you've noticed that the UI could use
- 10:43some updating to Mac UI that we started
- 10:46with the housing location images are too
- 10:48big and the items are not listed in a
- 10:51grid because we're focusing on angular
- 10:53and not CSS I'm going to provide you
- 10:56with all of the style updates you need
- 10:58to make to the code at this URL
- 11:01goo.gle forward slash homes Dash app
- 11:05dash styles each update will be listed
- 11:08with instructions and you can copy and
- 11:10paste the changes from there into your
- 11:12application
- 11:13all right with the Styles applied save
- 11:16all files check the browser and you
- 11:18should find that our application matches
- 11:20the original design great job friends
- 11:23really fantastic work
- 11:25in this module we've done a lot so let's
- 11:29recap
- 11:30we built the structure for our housing
- 11:32component we made the component
- 11:34customizable with the use of inputs so
- 11:37that we could display each component
- 11:38with the correct data we updated the
- 11:41template to use the ng4 directive in
- 11:43order to iterate over the housing
- 11:45location array to display each location
- 11:48and finally we added some styling to the
- 11:51application to make it render like the
- 11:54screenshots okay that is a really really
- 11:57great work you should be very proud of
- 11:59yourself and in the next section we'll
- 12:01update the app to support routing very
- 12:04exciting and I'll catch you in the next
- 12:06chapter
- 12:09foreign
- 12:11[Music]
About this transcript
This page contains the full transcript of Customizing components and directives (Part 4) by Angular, generated from the public captions YouTube serves with the video. The transcript has 1,762 words across 290 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.