3 Best Guidelines To Earn Money From Online

If you want to choose the best way to earn money from Online, check this post. Don't choose multiple sectors, just focus on a sector you will get success very early.

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Intro to Angular

Angular!!!

The two most popular JavaScript frameworks these days are React and Angular (otherwise known as Angular 2, Angular 2+ or Angular 5).

I recently started a new job where we use both frameworks and I hadn’t ever used Angular. I’ve just started to learn it and wanted to share some high-level information about it as a starting point for developers, especially junior developers who may feel overwhelmed taking on a new framework.

The first thing you will need to do is open up your terminal and install Angular. For this you will also need Node. If you don’t have node it’s recommended to install it using nvm (node version manager) instead of npm (node package manager) for ease transitioning between different versions of node.

To install Angular the command is:

npm install angular

I recommend installing globally so that you aren’t re-installing Angular on every project:

npm install -g angular

To install the Angular CLI the command is:

npm install -g @angular/cli

And now you’re ready to create your first Angular app! There’s a lot going on in this framework but I will highlight a few things that are good to understand before you dive deeper on your own (I’m just learning it too!).

If you have some experience writing JavaScript but you are new to TS, the most important thing to know is that TS is a language that compiles to good old JS. The browser does not speak TS, it speaks JS. So similarly, if you have used SASS/SCSS to write styles, you probably know that this compiles into regular old CSS for the browser to understand it.

2. Angular helps you build single page applications.

The browser only loads a single HTML page, but it changes dynamically as the user interacts with it. As things change, the entire app is not reloading, only the parts of it that need to reload change allowing the application to be much more performant. Think of an application like facebook (which uses React). You don’t want the entire application to reload every time a user writes a comment or likes something, SPAs allow for just that thing to update.

3. Angular uses components.

Components represent the various building blocks of the application that are composed together. There is the App component which contains everything (and is the one component that the index.HTML page needs to interact with) and then there are other components that feed into this App component. You might have a header component, a button component, a gallery component, etc, but ultimately they all come together in the App component and this gets compiled into the HTML, CSS and JS that the browser renders.

Building Components:

The Angular CLI will set up the App component for you when you create a new project. The command to build a new project is:

ng new NAME (the name being the name of the project you are making)

Hot tip: Make sure you then cd into your new project before doing anything else. Once you are in that folder you can load the project in the CLI with the command:

ng serve

And just like that you have an app! Your command line will tell you that the localhost is listening (localhost:4200) which you can type into the browser to see your app!

To create a new component simply exit the program in your terminal (you won’t be able to do it with ng serve running) and type in the command:

ng g c NAME (aka ng generate component NAME)

This will create a new component that is hooked up already and feeding into the App component properly. You can build your own components from scratch too, but this is the best route to go until you are a little bit more comfortable working in the CLI.

Anatomy of a component:

Each component has 3 primary files (a fourth spec file is generated by the CLI but we don’t need to interact with this at this stage in our Angular game).

Within the TS file there are 3 parts as well.

That looks like this:

import { Component } from ‘@angular/core’;

2. The decorator goes in the middle. This is where you connect the HTML template and CSS file to the component and where you give the component a selector name (allowing it to be selected by the App component). There are lots of properties that could go in the decorator, but these are the basics to start with.

That looks like this:

@Component({

selector: ‘app-header’,

templateUrl: ‘header.component.html’,

styleUrls: [‘header.component.css’]

})

The reason the templateUrl is singular and the styleURLs is plural with square brackets is that you will only have one HTML template for any component but you could potentially have several style sheets in this array.

3. An export class at the bottom. This allows you to export the contents of the component so that other components can import it. This is also where any functionality for the component gets written.

On the most basic level that looks like this:

export class HeaderComponent {}

I hope this article helps with the beginning phases of learning Angular! It’s definitely a rabbit hole that goes very deep, should you choose to go there, but on the highest level you can literally create an entire functioning application in a handful of commands, and that is pretty sweet if you ask me!

Add a comment

Related posts:

Winning the War for Talent as a Small Business

Many small businesses that have or need employees assume the false premise that employees need to come in trained. They feel that it is the employee’s responsibility to train themselves and that…

The simplest growth hack for Fintech marketers

Blackrock is the ultimate Wall Street behemoth with over $6 trillion in assets under management (AuM). No other firm ever has managed so much money. On Facebook, if you search for “Blackrock”, a…

Why Hate People Who Love Money?

Aadi was 7 when he first asked his parents to buy him a remote-control airplane that he had seen in cartoons but his parents gave him just a plane that didn’t fly because they couldn’t waste money on…