"HI", "title1", "objName11"
虽然我的 HTML 加载(由于span
顶部的标签而能够看到),但 ngb-accordion 不会在视图上呈现。我无法弄清楚我错过了什么。
没有编译/构建错误。控制台上没有错误。:(
我看到了一些关于 NGB-PRECOMPILE 的东西,这有必要吗?也无法在@ng-bootstrap/ng-bootstrap 中找到它。 https://stackoverflow.com/questions/38792108/precompile-error-on-ng-bootstrap-ngb-precompile
以下是代码片段,
(我通过删除onInit
我使用服务/可观察对象实际加载的实现来简化代码MyObject
,只是为了重点)
我的模板:./someComponent.Component.html:
<span>Hi<span>
<span>myObject.objList[0].title</span>
<span>myObject.objList[0].details[0].objName</span>
<ngb-accordion>
<ng-panel *ngFor="let myObj of myObject.objList">
<template ngbPanelTitle>
<span>{{myObj.title}}</span>
</template>
<template ngbPanelContent>
<div *ngFor="let detail of myObj.details" class="row">
<span>
{{detail.objName}}
</span>
</template>
</ng-panel>
</ngb-accordion>
零件:
import { Component, OnInit } from '@angular/core';
import { NGB_ACCORDION_DIRECTIVES } from '@ng-bootstrap/ng-bootstrap/accordion/accordion';
import { MyObject } from './MyObject.model';
@Component({
selector: 'some-selector',
templateUrl: './someComponent.Component.html',
directives: [ NGB_ACCORDION_DIRECTIVES ],
})
export class SomeComponent {
public myObject: MyObject = {
objList: [
{ title: "title1",
details: [{ objName: "objName11" },
{ objName: "objName12" }]
},
{ title: "title2",
details: [{ objName: "objName21" },
{ objName: "objName22" }]
}};
}
我的对象模型:
export class MyObject{
objList: ObjList[];
}
export class ObjList{
title:string;
details: Detail[];
}
export class Detail{
objName:string;
}