首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用角为2的Packery

使用角为2的Packery
EN

Stack Overflow用户
提问于 2017-02-09 15:23:08
回答 1查看 2.4K关注 0票数 6

我似乎无法让帕克利使用角2使用角cli和类型记录2.0。我使用Packery 1.4.1和DefinitelyTyped对该版本的类型记录定义。

问题是,在运行带有ng服务的项目时,无法找到对外露层的Packery引用。

具体而言,引发以下异常的原因是:

TypeError:无法设置未定义的Object.utils.extend的属性“位置”( Cannot webpackJsonp.82.module.exports )

下面是我的项目代码。

角-cli.json中的脚本部分:

代码语言:javascript
复制
"scripts": [
        "../node_modules/packery/dist/packery.pkgd.js"],

我也尝试过添加依赖的js文件,但是引发的异常是相同的:

代码语言:javascript
复制
"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:

代码语言:javascript
复制
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

代码语言:javascript
复制
<div #grid class="grid">
  <div class="grid-item"></div>
  <div class="grid-item"></div>
</div>

我想要帮助如何使Packery运行在角2与或不打字(香草js对我来说是可以的)。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-15 07:37:33

上面的问题是,我没有使用网格的"nativeElement“属性。这将起作用:

代码语言:javascript
复制
var packery = new Packery(this.grid.nativeElement, {
itemSelector: '.grid-item', columnWidth: 100 });

另外,角-cli脚本部分中唯一需要的脚本是:

代码语言:javascript
复制
"scripts": [
        "../node_modules/packery/dist/packery.pkgd.js"        
        ]

要添加可拖动性,请使用"npm安装可拖动性--保存“,并将另一个脚本添加到角-cli的脚本部分:

代码语言:javascript
复制
"scripts": [
        "../node_modules/packery/dist/packery.pkgd.min.js",
        "../node_modules/draggabilly/dist/draggabilly.pkgd.min.js"        
        ]

然后也更新组件类:

代码语言:javascript
复制
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 );
      });         
  }
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42140537

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档