我使用angular 4来创建我的网站。但是我需要在里面创建一个带有对象的对象。这不适合我。我的代码:
对象1(disciplinaStatus.module.ts)
export class DisciplinaStatus{
constructor(public codigo: string,
public nome: string,
public status: string,
public professor:string,
public cargaHoraria:string,
public nota: number) {}
}
对象2(historicoData.module.ts)
import { DisciplinaStatus } from './disciplinaStatus.model';
export class HistoricoData{
constructor(public periodo: string,
public historico: DisciplinaStatus[]) {} //The Problem stay here!!!
}
我的组件ts代码:
import { Component, OnInit } from '@angular/core';
import { DisciplinaStatus } from './models/disciplinaStatus.model';
import { HistoricoData } from './models/historicoData.model';
@Component({
selector: 'historico-a-component',
templateUrl: './historico-a.component.html',
styleUrls: ['./historico-a.component.css']
})
export class HistoricoAComponent implements OnInit {
constructor(historico: HistoricoData[]) {
historico = [
new HistoricoData('2016/1', [
new DisciplinaStatus('001','Redes 1','Completo','Everthon Valadão','60',71.5),
new DisciplinaStatus('002','Compiladores','Completo','Walace','60',45.5)
]),
new HistoricoData('2016/2', [
new DisciplinaStatus('001','AED','Completo','Diego Melo','60',22.5),
new DisciplinaStatus('002','Teoria','Completo','Diego Melo','60',89.5)
])
];
}
错误:
ng:///AppModule/AppComponent.ngfactory.js:7错误错误: StaticInjectorError(AppModule)[HistoricoAComponent - >阵列]:
StaticInjectorError(Platform:core)[HistoricoAComponent - >阵列]: NullInjectorError:没有Array的提供者! 在 NullInjector.get(webpack-internal:///../../../core/esm5/core.js:1209) at resolveToken(webpack-internal:///../../../core/esm5/core.js:1507) 在tryResolveToken(webpack-internal:///../../../core/esm5/core.js:1449) 在StaticInjector.get(webpack-internal:///../../../core/esm5/core.js:1317) at resolveToken(webpack-internal:///../../../core/esm5/core.js:1507) 在tryResolveToken(webpack-internal:///../../../core/esm5/core.js:1449) 在StaticInjector.get(webpack-internal:///../../../core/esm5/core.js:1317) at resolveNgModuleDep(webpack-internal:///../../../core/esm5/core.js:11051) 在NgModuleRef .get(webpack-internal:///../../../core/esm5/core.js:12284) at resolveDep(webpack-internal:///../../../core/esm5/core.js:12774)
答案 0 :(得分:0)
看起来您正在使用构造函数来声明属性。只需在类中声明属性并将其从构造函数参数中删除,这样角度就不会认为它应该注入somrthing,因为你要覆盖它。