-
angular.json
: 워크스페이스에 있는 모든 프로젝트에 적용되는 Angular CLI 환경설정파일. 빌드, 실행, 테스트할 때 사용하는 설정도 이 파일에서 구성
- sourceRoot : src: 프로젝트의 루트 폴더는 src 폴더인 것을 알수 있음
- outputPath : dist/first-app : 프로젝트 빌드시 dist폴더 생성
- index : src/index.html : 인덱스 파일은 index.html 파일
- browser : src/main.ts : 시작 지점이자 메인 파일은 main.ts 파일

-
indext.html

- 웹사이트에 접근한 사용자가 보게 되는 메인 html 파일
- javascript 파일과 css파일은 angular cli가 빌드 시점에 자동으로 index.html 파일에 추가하기 때문에 script 태그나 link 태그를 수동으로 작성할 필요가 없다
- body 부분에는 app-root 셀렉터가 들어감
-
main.ts파일
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.error(err));
- 애플리케이션의 메인 진입점으로 우리가 만든 코드들의 컴파일을 브라우저에 담당
- JIT 컴파일러를 사용하면 이 파일을 기준으로 어플리케이션의 최상위 모듈 부트스트랩
- 소스에서 AppModule 변수는 app.module.ts파일 참조
-
app.module.ts파일
import { NgModule } from '@angular/core';
import { BrowserModule, provideClientHydration } from '@angular/platform-browser';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
@NgModule({
declarations: [ // 컴포넌트, 지시자, 파이프 등이 들어옴
AppComponent
],
imports: [ // 다른 모듈들이 들어옴
BrowserModule,
AppRoutingModule
],
providers: [ // View가 없는 서비스 로직들이 들어옴
provideClientHydration()
],
bootstrap: [AppComponent] // 처음 실행할 컴포넌트를 지정함
})
export class AppModule { }
- 어플리케이션 구성이 시작될 최상위 모듈 AppModule을 정의. 프로젝트 생성시 AppComponent만 존재하지만, 앱이 커질수록 컴포넌트도 늘어남
- NgModule 데코레이터를 사용했으며, AppComponent를 부트스트랩이라고 한다고 정의
- 맨 하단의 import, export 문법은 ES6에서 제공하는 모듈 시스템
-
AppComponet 관련 파일
- AppComponet는 최상위 컴포넌트에 해당, 하나의 컴포넌트가 각자 역할에 따라 분리
- app.component.ts : 최상위 컴포넌트 AppComponent 정의
- app.component.html : 최상위 컴포넌트 html 태블릿 정의
- app.component.css : 최상위 컴포넌트 css 스타일 정의
- app.component.sepc.ts : 유닛테스트 스펙 정의
- 또한, ng generate 명령어를 이용하면 컴포넌트를 만들 수 있음. 컴포넌트 생성시 위 4개 파일이 세트로 만들어짐.
-
app.component.ts 파일
import { Component } from '@angular/core';
@Component({
selector: 'app-root', // CSS 셀렉터 같은 선택자
templateUrl: './app.component.html', // 뷰에 대한 정의
styleUrl: './app.component.css' // 스타일에 대한 정의
})
export class AppComponent {
title = '개발새발';
}
- 사용자가 보는 화면은 최상위 컴포넌트인 AppComponent를 기준으로 구성된 뷰 계층. 개발자가 구현한 컴포넌트와 서비스도 AppComponent안에 동작
- @의 의미는 TypeScript에서 제공하고 있는 데코레이터를 의미 @Component는 단순한 클래스가 아닌 ngAngular Component이라는 것을 정의한 클래스
- 컴포넌트의 셀렉터가 app-root로 설정되어 있기 때문에 index.html 파일의 app-root에 해당 컴포넌트가 들어가짐. 셀렉터는 #app-todos 또는 .app-todos처럼 특정 엘리먼트를 선택 가능하고 또는 엘리먼트 이름이 <app-root>인 dom을 가르킬 수 있음
- templateUrl은 app.component.html 파일로 설정되어 있고, styleUrl은 app.component.css 파일로 설정. AppComponent 클래스의 title 속성은 아래 html과 바인딩 되어 템플릿에 표현 됨
-
app.component.html 파일
<div>
{{ title }}
</div>
