【发布时间】:2017-02-09 15:23:08
【问题描述】:
我似乎无法让 Packery 使用 angular-cli 和 typescript 2.0 与 Angular 2 一起工作。 我正在使用 Packery 1.4.1 和该版本的打字稿定义。
问题是在使用 ng serve 运行项目时,找不到对 Outlayer 的 Packery 引用。
具体来说会抛出以下异常:
TypeError:无法设置未定义的属性“位置” 在 Object.utils.extend (eval at webpackJsonp.82.module.exports
下面是我的项目代码。
来自 angular-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 在 Angular 2 中运行,无论是否有类型(vanilla js 对我来说都可以)。
【问题讨论】:
标签: angular webpack angular-cli packery