• Complain

Shreeharsh Ambli - Your First Angular Component

Here you can read online Shreeharsh Ambli - Your First Angular Component full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2017, genre: Home and family. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Shreeharsh Ambli Your First Angular Component

Your First Angular Component: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Your First Angular Component" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Shreeharsh Ambli: author's other books


Who wrote Your First Angular Component? Find out the surname, the name of the author of the book and a list of all author's works by series.

Your First Angular Component — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Your First Angular Component" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make

Your First Angular Component

Copyright 2017, Shreeharsh Ambli. All Rights Reserved.

Who should read this guide?

Although this guide explains any new concepts before first use, its not designed to replace official documentation and other beginner books in the market. This guide helps you understand how to leverage different Angular concepts to create re-usable components.

We will be creating a star rating component from scratch to begin with. We will also create a Pie / Donut Chart component and will use Google Charts this would be more in line with real world development.

This is what you will end up with after finishing this guide:

Lets get started already Getting Started First things first we need your - photo 1

Lets get started already Getting Started First things first we need your - photo 2

Lets get started already!

Getting Started

First things first, we need your computer setup for Angular development. Please follow online resources and get the following in place before you continue:

  1. Install Visual Studio Code
  2. Install NodeJS
  3. Install Angular CLI using NPM:


NodeJS is the best way to get NPM which is a package manager Angular CLI is - photo 3

NodeJS is the best way to get NPM, which is a package manager. Angular CLI is the recommended way to develop on Angular. It also generates code that meets all recommended standards / conventions.

Tip

The g option tells NPM to install the Angular CLI globally.

Please refer to online help on NPM and Angular CLI in case of any issues.

Star Rating Component

Lets use the Angular CLI (Command Line Interface) to create our first Angular application and the star rating component.

Run the following command to create the new star-rating app:

This will create a new folder named star-rating and will ready all the - photo 4

This will create a new folder named star-rating and will ready all the necessary plumbing for your new application. It would take some time to finish off so please be patient.

Once done, open the folder that the CLI created and run the following command to see if all worked OK:

Your First Angular Component - image 5

This command builds and deploys your app locally. The open option automatically opens the browser for you. If you forget to set this option, you will need to open http://localhost:4200/ manually to see the application.

Angular CLI

Please visit https://github.com/angular/angular-cli/wiki for more details on Angular CLI commands.

Keep both the terminal and the browser open henceforth. Any change you make to code will automatically refresh in the browser.

Open the folder in Visual Studio Code before proceeding. You should see a file structure similar to below:

Digging deeper we see that the Angular CLI has created the default App - photo 6

Digging deeper, we see that the Angular CLI has created the default App component for us:

Lets add a new component for our star rating To do so run the following - photo 7

Lets add a new component for our star rating. To do so run the following command:

You should now be able to see a new folder and new files under the same for our - photo 8

You should now be able to see a new folder and new files under the same for our new component:

Now that we have all the plumbing in place thanks to Angular CLI we can get - photo 9

Now that we have all the plumbing in place, thanks to Angular CLI, we can get coding.

Angular CLI

For more details on generating various items using the CLI, please see https://github.com/angular/angular-cli/wiki/generate

Open up the star-rating.component.ts file and rename the selector to star-rating:

Now open up the appcomponenthtml and replace all text with below It - photo 10

Now, open up the app.component.html and replace all text with below:

It would be intuitive to pass the rating value as an input thus the above - photo 11

It would be intuitive to pass the rating value as an input, thus the above code. Now lets start work on the star rating component.

Add a new input properly for the rating value in the StarRatingComponent class (star-rating.component.ts file):

Lets see what we have accomplished for now Simply switch to the browser and it - photo 12

Lets see what we have accomplished for now. Simply switch to the browser and it should have automatically refreshed after you have saved all your changes:

Replace all existing text in the star-ratingcomponenthtml with - photo 13

Replace all existing text in the star-rating.component.html with:

Switching to the browser we now see our passed rating value Now this is - photo 14

Switching to the browser, we now see our passed rating value:

Now this is a very good example to use Angular Pipes Pipes basically formats - photo 15

Now, this is a very good example to use Angular Pipes. Pipes basically formats / converts a value from one form to another thats more suitable to display. In our case, we need to convert a number to show stars.

To show a filled star, we can use ★ and to show an empty star use ☆ html names / codes. So lets add a new pipe to our component. Make sure you are in the star-rating component folder before creating the pipe by using the below command, else the pipe will be created under the app component:

You should now see the new pipe created under the star-rating component - photo 16

You should now see the new pipe created under the star-rating component:

Replace the existing transform method with the below star-formatterpipets - photo 17

Replace the existing transform method with the below (star-formatter.pipe.ts file):

You could use a more optimal logic to do the same Basically we are taking in - photo 18

You could use a more optimal logic to do the same. Basically we are taking in the rating value and returning back those many filled stars appended with any empty stars so that total stars are always 5.

We need to update the star rating components html to use this new pipe, like so:

Switching to the browser brings up our star rating component now showing - photo 19

Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Your First Angular Component»

Look at similar books to Your First Angular Component. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Your First Angular Component»

Discussion, reviews of the book Your First Angular Component and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.