【发布时间】:2018-07-18 22:58:39
【问题描述】:
我正在尝试在没有 ngx-fullapge 的情况下使用 fullpage.js,但我遇到了一些与导入相关的问题:
首先,jquery 似乎不起作用,即使包已设置...
在一个非常简单的AppComponent 类定义中,我有:
import { Component, OnInit } from '@angular/core';
import * as $ from 'jquery';
import * as fullpagejs from 'fullpage.js';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ],
})
export class AppComponent implements OnInit {
public items = [1, 2, 3];
public ngOnInit() : void {
$('#fullpage')
}
}
使用非常简单的模板:
<div id="fullpage">
<div class="section" id="landing">
Landing
</div>
<div class="section" *ngFor="let item of items; let i = index" id="document_{{ i }}">
Document {{ item }}
</div>
<div class="section" id="general-information">
General Information
</div>
</div>
angular.json 的脚本如下:
"scripts": [
"./node_modules/jquery/dist/jquery.min.js",
"./node_modules/fullpage.js/dist/jquery.fullpage.min.js"
]
我有以下错误:
ERROR
Error: $ is not a function
我在这里创建了一个重现问题的在线项目:https://stackblitz.com/edit/angular-nrrujn
如何在这个项目中同时使用 jQuery 和 fullpage.js?
[编辑]
jQuery 可与 import $ from 'jquery'; 一起使用,但仍无法找到 fullpage.js 中的 fullpage() 方法。
我更新了stackblitz:https://stackblitz.com/edit/angular-nrrujn
【问题讨论】:
-
尝试将
declare var $: any添加到AppComponent。 -
现在 fullPage.js 可用于 Angular:github.com/alvarotrigo/angular-fullpage
标签: javascript jquery angular fullpage.js