我正在尝试使用fullpage.js,而不使用ngx,而且我面临一些与进口有关的问题:
首先,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
发布于 2018-07-19 14:48:26
2018年11月更新:
现在,fullPage.js可用于角:https://github.com/alvarotrigo/angular-fullpage
不是角质方面的专家但是..。也许您应该在导入窗口对象后在其上声明$?
那这个呢?
import { Component, OnInit } from '@angular/core';
import jQuery from 'jquery'; // <--- change here
import * as fullpagejs from 'fullpage.js';
if(!window.$){
window.$ = jQuery;
}发布于 2018-09-02 12:39:16
确保jquery.fullpage.min.js文件存在于'./node_modules/fullpage.js/dist/jquery.fullpage.min.js'目录中
发布于 2018-07-19 15:09:05
行import * as $ from 'jquery';绝对是正确的。
确保jquery实际安装在您的项目中。运行npm install jquery@latest来安装它。然后从scripts数组中删除它,因为它不属于那里。
https://stackoverflow.com/questions/51412089
复制相似问题