我嘗試addItems
但是方法調用,我是得到錯誤:如何在DOM中與Angular 4應用程序進行通信?
Uncaught TypeError: this.addItems is not a function
我用角4 jQuery和fullpage.js庫。
頁面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);
});
}
}
}
@RahulDagli你剛纔的問題被關閉爲重複的問題。這意味着你被賦予了一個鏈接到重複你的問題。請繼續閱讀。不要再問同樣的問題。 – Duncan