2017-07-04 3 views
-2

私はしかし、私は取得エラーだaddItemsメソッドを呼び出すようにしてみてください。Angular 4アプリでDOMと通信するには?</p> <blockquote> <p>Uncaught TypeError: this.addItems is not a function</p> </blockquote> <p>私はjQueryとfullpage.jsライブラリと角度4を使用しています:

ページ-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); 
     }); 
    } 
    } 
} 
+3

の問題を持っています。それは、あなたの質問に答える複写物へのリンクが与えられたことを意味します。行って読んでください。もう一度同じ質問をしないでください。 – Duncan

答えて

0

I)は、(コンストラクタからngOnInitにこの呼び出しを移動する

constructor(private newService: MyDataService) { 
    this.addItems(0, this.no_of_post); 
} 

そして事をお勧めしたいその上thisポイントということですクラス。あなたはそのクラスにプロパティno_of_postを持っていません。

また、あなたは、この文字列

onLeave: function(index, nextIndex, direction) {

使用矢印機能以前の質問が重複として閉じた@RahulDagli

onLeave: (index, nextIndex, direction) => {

+2

質問は重複としてマークされていますが、重複しています。重複する質問には回答しないでください。 – Alex

関連する問題

 関連する問題