I am trying to call the addItems
method, but I keep getting an error:
Uncaught TypeError: this.addItems is not a function
Currently, I am using Angular 4 along with jQuery and the fullpage.js library.
page-content.component.ts
import { Component, OnInit } from '@angular/core';
import { MyDataService } from './my-data.service';
import * as $ from 'jquery';
import 'fullpage.js';
@Component({
selector: 'page-content',
providers: [MyDataService],
templateUrl: './page-content.component.html',
styleUrls: ['./page-content.component.css']
})
export class PageContentComponent implements OnInit {
single_post = '';
posts = [];
constructor(private newService: MyDataService) {
this.addItems(0, this.no_of_post);
}
ngOnInit() {
$(document).ready(function() {
if($('html').hasClass('fp-enabled')){
$.fn.fullpage.destroy('all');
}
$('#fullpage').fullpage({
onLeave: function(index, nextIndex, direction){
const start = this.no_of_post;
this.no_of_post += 1;
this.addItems(start, this.no_of_post);
}
});
});
}
addItems(startIndex, endIndex) {
for (let i = startIndex; i < this.no_of_post; ++i) {
this.newService.fetchData().subscribe(data=>{
this.single_post = data[i];
this.posts.push(this.single_post);
});
}
}
}