目录
一、修改根模块
在src\app\app.module.ts中,导入数据源模块(ModelModule),修改后的文件为
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { ModelModule } from './model/model.module';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
ModelModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
二、修改根组件的 ts
在src\app\app.component.ts中,声明章节数组,并在构造函数中注入数据源,修改后的文件为
import { Component } from '@angular/core';
import { Chapter } from './model/chapter.model';
import { StaticDataSource } from './model/static.data.source';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
public chapters: Chapter[] = [];
constructor(private dataSource: S