组件,是整个应用的基础。下图是组件的必备元素。javascript
import { Component } from '@angular/core'; @Component({ selector: 'app-root',//css选择器的名称,能够在模板中使用。 templateUrl: './app.component.html',//指向组件使用的模板文件 styleUrls: ['./app.component.css']//指向组件用到的样式文件 }) export class AppComponent { //AppComponent 是一个标准的typescript类 title = 'app'; }
@Component能够当作一个注解,注解了AppComponent类是一个组件。经过这个注解,Angular知道应该将AppComponent类看成一个组件来处理。css
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; @NgModule({ declarations: [//声明组件,管道和指令 AppComponent, ], imports: [//引用的组件 BrowserModule FormModule, HttpModule ], providers: [],//在这里声明服务 bootstrap: [AppComponent]//声明了模块的主组件 }) export class AppModule { }
@NgModule()装饰器html
启动时加载了哪一个页面?java
启动时加载了哪些脚本?typescript
这些脚本作了什么事?bootstrap