我刚开始玩angular2并试图用css-animator
做一些动画的package.json
"dependencies": {
"@angular/common": "2.0.0-rc.3",
"@angular/compiler": "2.0.0-rc.3",
"@angular/core": "2.0.0-rc.3",
"@angular/forms": "0.1.1",
"@angular/http": "2.0.0-rc.3",
"@angular/platform-browser": "2.0.0-rc.3",
"@angular/platform-browser-dynamic": "2.0.0-rc.3",
"@angular/router": "3.0.0-alpha.7",
"@angular/router-deprecated": "2.0.0-rc.2",
"@angular/upgrade": "2.0.0-rc.3",
"angular2-in-memory-web-api": "0.0.12",
"bootstrap": "^3.3.6",
"chokidar": "^1.6.0",
"core-js": "^2.4.0",
"css-animator": "^1.2.4",
"http-proxy": "^1.14.0",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.6",
"systemjs": "0.19.27",
"zone.js": "^0.6.12"
}
的index.html
<html>
<head>
<title>Angular 2 QuickStart</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="app/css/bootstrap.css">
<link rel="stylesheet" href="app/css/style.css">
<!-- 1. Load libraries -->
<!-- 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="node_modules/css-animator/builder/animation_builder.js"> </script>
<!-- 2. Configure SystemJS -->
<script src="systemjs.config.js"></script>
<script>
System.import('app').catch(function(err){ console.error(err); });
</script>
</head>
<!-- 3. Display the application -->
<body class="bg-image">
<my-app>Loading...</my-app>
</body>
</html>
systemjs.config.js
var map = {
'app': 'app', // 'dist',
'@angular': 'node_modules/@angular',
'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
'rxjs': 'node_modules/rxjs',
'css-animator': 'node_modules/css-animator'
};
var packages = {
'app': { main: 'main.js', defaultExtension: 'js' },
'rxjs': { defaultExtension: 'js' },
'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' },
};
System.config(config);
custom.animate.directive.ts
import {Directive, ElementRef, Renderer} from '@angular/core';
import {AnimationService, AnimationBuilder} from 'css-animator';
@Directive({
selector: '[login-method]',
host: {
'(click)':'onClick()'
}
})
export class LoginOptionsDirective{
private animator : AnimationBuilder;
constructor(animationService: AnimationService, private el: ElementRef, private renderer: Renderer){
this.animator = animationService.builder();
}
onclick(){
this.renderer.setElementStyle(this.el, 'color','black');
console.log(this.el.nativeElement.getAttribute("login-method"));
}
}
我在浏览器控制台上获得了animation_builder.js:434 Uncaught ReferenceError: exports is not defined
和localhost/:18 Error: Error: XHR error (404 Not Found) loading http://localhost:3000/node_modules/css-animator(…)
。
有人可以帮我这个吗?
感谢。
答案 0 :(得分:2)
您将animation_builder.js
直接包含在<head>
部分中:
<script src="node_modules/css-animator/builder/animation_builder.js"></script>
你得到一个ReferenceError,因为css-animator包中包含的单个文件被编译成CommonJS,浏览器本身并不理解。
尝试删除该行,如果您将文件导入某处,SystemJS应自动加载这些文件。 SystemJS也了解CommonJS。
或者,您可以在<head>
部分中包含程序包提供的SystemJS包。如果您从css-animator导入模块,SystemJS已经注册了该模块,可以立即加载它。
您可以包含缩小或未缩小的捆绑包,如下所示:
<!-- Unminified Source -->
<script src="node_modules/css-animator/bundles/css-animator.js"></script>
<!-- Minified Source -->
<script src="node_modules/css-animator/bundles/css-animator.min.js"></script>
免责声明:我是这个软件包的作者。