BookBlock プラグインを Angular で動作させるのに問題があります。関数「ngAfterViewInit」で BookBlock オブジェクトが作成されたのは時期尚早であり、DOM はまだ使用する準備ができていないようです。
コンポーネントコードは次のとおりです。
import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Skill } from './skill';
import { SkillService } from './skill.service';
declare var BookBlock: any;
@Component({
moduleId: module.id,
selector: 'skill-list',
templateUrl: './template/skill-list.component.html',
styles: ['.skills {list-style-type: none;}', '*.skills li {padding:
4px;cursor: pointer;}']
})
export class SkillListComponent implements OnInit {
skills: Observable<Skill[]>;
bbArea: HTMLElement;
bookBlock: any;
constructor(private skillService: SkillService) {}
ngOnInit() {
this.skills = this.skillService.getSkills();
}
ngAfterViewInit() {
this.bbArea = document.getElementById("blockbook");
this.bookBlock = new BookBlock(this.bbArea, {
speed: 500,
shadowSides: 0.8,
shadowFlip: 0.7
});
}
}
ここにビューがあります:
<article>
<h4>My Skills</h4>
<div class="bb-custom-wrapper">
<div id="blockbook" class="bb-bookblock" >
<div *ngFor="let skill of skills | async" class="bb-item">
<a href="" [routerLink]="['/skills', skill.id]">
{{skill.id}}. {{skill.name}}
</a>
</div>
</div>
</div>
</article>
エラーは次のとおりです。
core.umd.js:1091 ERROR Error: Uncaught (in promise): TypeError: Cannot read
property 'style' of undefined
TypeError: Cannot read property 'style' of undefined
at BookBlock._init (bookblock.js:111)
at new BookBlock (bookblock.js:47)
at SkillListComponent.ngAfterViewInit (skill-list.component.ts:26)
実際のエラー行は次のとおりです。
...
// previous item´s index
this.previous = -1;
// show first item
this.current = this.items[this.currentIdx];
***this.current.style.display = 'block';***
// get width of this.el
// this will be necessary to create the flipping layout
this.elWidth = this.el.offsetWidth;
var transEndEventNames = {
'WebkitTransition': 'webkitTransitionEnd',
'MozTransition': 'transitionend',
...
さらに情報が必要な場合はお知らせください。ありがとう!