Setting Up a New Project
Greenhouse needs a home on your computer. You could wire up TypeScript, a bundler, a test runner and a dev server by hand, but Angular ships a tool that does all of it in one command. Learn three commands and you can start any Angular project.
The rule
ng newcreates,ng serveruns,ng generateadds.
Everything goes through the Angular CLI, a command-line tool installed with npm. You need Node.js first.
npm install -g @angular/cli # once per computer
ng new greenhouse # create the project
cd greenhouse
ng serve # run it at http://localhost:4200ng new asks a few questions (such as which stylesheet format to use), creates the folder and installs packages. ng serve compiles the app, serves it locally, and rebuilds and refreshes the browser every time you save.
The files that matter first:
src/index.html— the single HTML page; it contains the root tag<app-root>.src/main.ts— the starting point. It callsbootstrapApplicationwith the root component.src/app/— your components. The root one is theAppclass (calledAppComponentin older projects).src/app/app.config.ts— app-wide setup such as the router and HTTP client.angular.jsonandpackage.json— build settings and dependencies.
// src/main.ts
import { bootstrapApplication } from '@angular/platform-browser';
import { appConfig } from './app/app.config';
import { App } from './app/app';
bootstrapApplication(App, appConfig);To add pieces, let the CLI write the boilerplate:
ng generate component plant-card # short form: ng g c plant-card
ng generate service plant # short form: ng g s plant