我似乎无法让帕克利使用角2使用角cli和类型记录2.0。我使用Packery 1.4.1和DefinitelyTyped对该版本的类型记录定义。
问题是,在运行带有ng服务的项目时,无法找到对外露层的Packery引用。
具体而言,引发以下异常的原因是:
TypeError:无法设置未定义的Object.utils.extend的属性“位置”( Cannot webpackJsonp.82.module.exports )
下面是我的项目代码。
角-cli.json中的脚本部分:
"scripts": [
"../node_modules/packery/dist/packery.pkgd.js"],我也尝试过添加依赖的js文件,但是引发的异常是相同的:
"scripts": [
"../node_modules/packery/dist/packery.pkgd.js",
"../node_modules/get-size/get-size.js",
"../node_modules/outlayer/outlayer.js",
"../node_modules/ev-emitter/ev-emitter.js",
"../node_modules/fizzy-ui-utils/utils.js",
"../node_modules/desandro-matches-selector/matches-selector.js"
],app.component.ts:
import { Component, ViewChild, AfterViewInit } from '@angular/core';
declare var Packery: any;
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements AfterViewInit
{
@ViewChild('grid') grid;
private pckry: any;
constructor() {}
ngAfterViewInit(){
this.pckry = new Packery(this.grid, {
itemSelector: '.grid-item'});
}
}app.component.html
<div #grid class="grid">
<div class="grid-item"></div>
<div class="grid-item"></div>
</div>我想要帮助如何使Packery运行在角2与或不打字(香草js对我来说是可以的)。
发布于 2017-02-15 07:37:33
上面的问题是,我没有使用网格的"nativeElement“属性。这将起作用:
var packery = new Packery(this.grid.nativeElement, {
itemSelector: '.grid-item', columnWidth: 100 });另外,角-cli脚本部分中唯一需要的脚本是:
"scripts": [
"../node_modules/packery/dist/packery.pkgd.js"
]要添加可拖动性,请使用"npm安装可拖动性--保存“,并将另一个脚本添加到角-cli的脚本部分:
"scripts": [
"../node_modules/packery/dist/packery.pkgd.min.js",
"../node_modules/draggabilly/dist/draggabilly.pkgd.min.js"
]然后也更新组件类:
import { Component, ViewChild, AfterViewInit } from '@angular/core';
declare var Packery: any;
declare var Draggabilly: any;
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements AfterViewInit
{
@ViewChild('grid') grid;
constructor() {}
ngAfterViewInit(){
var packery = new Packery(this.grid.nativeElement, {
itemSelector: '.grid-item', columnWidth: 100 });
packery.getItemElements().forEach( function( itemElem ) {
var draggie = new Draggabilly( itemElem );
packery.bindDraggabillyEvents( draggie );
});
}
}https://stackoverflow.com/questions/42140537
复制相似问题