问题描述
我已按照此处的说明进行操作: https://github.com/valor-software/ng2-dragula/wiki#5-min-quickstart 以及此处: https://www.npmjs.com/package/ng2-dragula
I've followed the instructions here: https://github.com/valor-software/ng2-dragula/wiki#5-min-quickstart as well as here: https://www.npmjs.com/package/ng2-dragula
Angular-quickstart正在运行,根据:
Angular-quickstart is working, as per:
git clone https://github.com/angular/quickstart angular2-dragula-test
npm install
npm start
我的第一个Angular应用"(在浏览器中弹出-一切正常)
"My First Angular App" (pops up in in the browser - so everything is working)
我通过以下方式安装Dragula:
I install dragula by:
npm install ng2-dragula dragula --save
我用valor软件ng2-dragula Wiki(第一个链接)的确切内容替换了快速入门文件.
I replaced the quickstart files with the exact content of the valor-software ng2-dragula wiki (first link).
如果有人可以提供任何建议(关于未列出的关键步骤)或简单的健全性检查,将不胜感激.
If someone could provide any advice (about unlisted steps that are critical) or a simple sanity check it would be much appreciated.
推荐答案
这些是使用angular-quickstart设置ng2-dragula基本测试应用的完整说明(请参阅底部使用Angular-CLI更新" Angular-CLI):
These are the full instructions for using angular-quickstart to set up a ng2-dragula basic test app (see bottom section "UPDATE using Angular-CLI" if using Angular-CLI):
设置一个新的angular-quickstart项目:
Set up a new angular-quickstart project:
mkdir angular2-dragula-test
git clone https://github.com/angular/quickstart angular2-dragula-test
cd angular2-dragula-test
npm install
npm start
如果一切顺利,您应该有一个网页,指出我的第一个Angular 2应用程序",基本的angular2-quickstart正常运行,我们现在将添加dragula.
If all is well you should have a web page stating "My First Angular 2 App", the basic angular2-quickstart is working, we'll now add dragula.
npm install ng2-dragula dragula
在 index.html 中,我们将通过添加以下行来添加dragula.css:
In index.html we'll add the dragula.css by adding the following line:
<link rel="stylesheet" href="node_modules/dragula/dist/dragula.css">
这是我完整的 index.html 供参考:
<!DOCTYPE html>
<html>
<head>
<title>Angular QuickStart</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css">
<!-- dragula css -->
<link rel="stylesheet" href="node_modules/dragula/dist/dragula.css">
<!-- Polyfill(s) for older browsers -->
<script src="node_modules/core-js/client/shim.min.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/reflect-metadata/Reflect.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<script>
System.import('app').catch(function(err){ console.error(err); });
</script>
</head>
<body>
<my-app>Loading...</my-app>
</body>
</html>
systemjs.config.js (查找显示为"//***的两条注释",以下内容是dragula *********所必需的* ***********如果只想添加相关行):
systemjs.config.js (look for the two comments reading "//***the following is required by dragula********************" if you just want to add the relevant lines ):
/**
* System configuration for Angular samples
* Adjust as necessary for your application needs.
*/
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: 'app',
// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
'@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',
// other libraries
'rxjs': 'npm:rxjs',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api',
//***the following is required by dragula********************
'dragula': 'node_modules/dragula',
'ng2-dragula': 'node_modules/ng2-dragula',
'contra': 'node_modules/contra',
'atoa': 'node_modules/atoa',
'ticky': 'node_modules/ticky',
'crossvent': 'node_modules/crossvent/src',
'custom-event': 'node_modules/custom-event',
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
main: './main.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
},
'angular-in-memory-web-api': {
main: './index.js',
defaultExtension: 'js'
},
//***the following is required by dragula********************
'dragula': {main: 'dragula.js', defaultExtension: 'js'},
'ng2-dragula': {defaultExtension: 'js'},
'contra': {main: 'contra.js', defaultExtension: 'js'},
'atoa': {main: 'atoa.js', defaultExtension: 'js'},
'ticky': {main: 'ticky.js', defaultExtension: 'js'},
'crossvent': {main: 'crossvent.js', defaultExtension: 'js'},
'custom-event': {main: 'index.js', defaultExtension: 'js'},
}
});
})(this);
将DragulaModule导入 app.module.ts :
Import the DragulaModule in app.module.ts:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { DragulaModule } from 'ng2-dragula/ng2-dragula'; //THIS IS NEW***
@NgModule({
imports: [ BrowserModule, DragulaModule ], //ADDED DragulaModule***
declarations: [ AppComponent],
bootstrap: [ AppComponent ]
})
export class AppModule { }
将app.component.ts替换为以下内容:
Replace app.component.ts with the following:
import { Component } from '@angular/core';
import { DragulaService } from 'ng2-dragula/ng2-dragula';
@Component({
selector: 'my-app',
template: `<h1>My First Angular 2 App</h1>
<div>
<div class='wrapper'>
<div class='container' [dragula]='"first-bag"'>
<div>Drag/drop item 1</div>
</div>
<div class='container' [dragula]='"first-bag"'>
<div>Drag/drop item 2</div>
</div>
</div>
</div>
`,
viewProviders: [DragulaService],
styles: [`
.wrapper {
display: table;
}
.container {
display: table-cell;
background-color: rgba(255, 255, 255, 0.2);
width: 50%;
}
.container:nth-child(odd) {
background-color: rgba(0, 0, 0, 0.2);
}
.container div,
.gu-mirror {
margin: 10px;
padding: 10px;
background-color: rgba(0, 0, 0, 0.2);
transition: opacity 0.4s ease-in-out;
}
.container div {
cursor: move;
cursor: grab;
cursor: -moz-grab;
cursor: -webkit-grab;
}
.gu-mirror {
cursor: grabbing;
cursor: -moz-grabbing;
cursor: -webkit-grabbing;
}
`]
})
export class AppComponent { }
使用Angular-CLI更新
幸运的是,这些说明比上面的要求更简单:
Fortunately the instructions are easier than what is required above:
首先设置一个新项目,然后添加Dragula:
First set up a new project, and add Dragula:
ng new ngcli-dragula
cd ngcli-dragula
npm install ng2-dragula dragula
如果出现以下错误
npm install ng2-dragula dragula
[email protected] /home/quaterion/Development/ngcli-dragula
├── UNMET PEER DEPENDENCY @angular/[email protected]
├── UNMET PEER DEPENDENCY @angular/[email protected]
├─┬ [email protected]
│ ├─┬ [email protected]
│ │ ├── [email protected]
│ │ └── [email protected]
│ └─┬ [email protected]
│ └── [email protected]
└── [email protected]
然后,您需要升级angular-cli,也可能是升级npm的一个好主意:
Then you need to upgrade angular-cli, probably a good idea to upgrade npm too:
npm install npm -g
npm install -g @angular/cli
将以下行添加到index.html中:
Add the following line to your index.html:
<link rel="stylesheet" href="node_modules/dragula/dist/dragula.css">
将DragulaModule导入app.module.ts中(请参阅两个注释"//NEW"):
Import the DragulaModule in in app.module.ts (see the two comments "//NEW"):
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { DragulaModule } from 'ng2-dragula/ng2-dragula'; //NEW
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
DragulaModule//NEW
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
将DragulaService导入app.component.ts中(请参见两个注释"//NEW"):
Import the DragulaService in app.component.ts (see the two comments "//NEW"):
import { Component } from '@angular/core';
import { DragulaService } from 'ng2-dragula/ng2-dragula';//NEW
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
viewProviders: [DragulaService]//NEW
})
export class AppComponent {
title = 'app works!';
}
更新html(app.component.html),因此有一个有效的示例:
Update the html (app.component.html) so there is a working example:
<h1>
{{title}}
</h1>
<div>
<div class='wrapper'>
<div class='container' [dragula]='"first-bag"'>
<div>Drag/drop item 1</div>
</div>
<div class='container' [dragula]='"first-bag"'>
<div>Drag/drop item 2</div>
</div>
</div>
</div>
现在有一个可行的示例,此CSS可选块将使示例看起来更好(app.component.css):
Now there is a working example, this optional block of CSS will make the example look nicer (app.component.css):
.wrapper {
display: table;
}
.container {
display: table-cell;
background-color: rgba(255, 255, 255, 0.2);
width: 50%;
}
.container:nth-child(odd) {
background-color: rgba(0, 0, 0, 0.2);
}
.container div,
.gu-mirror {
margin: 10px;
padding: 10px;
background-color: rgba(0, 0, 0, 0.2);
transition: opacity 0.4s ease-in-out;
}
.container div {
cursor: move;
cursor: grab;
cursor: -moz-grab;
cursor: -webkit-grab;
}
.gu-mirror {
cursor: grabbing;
cursor: -moz-grabbing;
cursor: -webkit-grabbing;
}
现在您应该有一个有效的示例.
Now you should have a working example.
这篇关于如何使用ng2-dragula设置angular-quickstart的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!