[英]I get an error in CreateJS: “createjs is not defined”
I have a problem with creatJS
I hope you can help. 我的creatJS
有问题,希望能对您有所帮助。
var stage = new createjs.Stage(canvas);
I got this error : 我收到此错误:
angular.js:13642 ReferenceError: createjs is not defined. angular.js:13642 ReferenceError:未定义createjs。 even thought i get the EaselJS in my bower-components. 甚至以为我在Bower组件中得到了EaselJS。
Thanks 谢谢
I assume createjs is defined in the window object. 我假设在窗口对象中定义了createjs。 To be accessible in angular js you need to make it injectabled like this : 为了在angular js中可访问,您需要像这样将其注入:
angular.module('myApp', [])
.constant('createjs', window.createjs)
Then you can inject it into your controller for example : 然后可以将其注入到控制器中,例如:
controller: function(createjs) {
var stage = new createjs.Stage(canvas);
}
You can also refer to it by using $window : 您也可以使用$ window来引用它:
controller: function($window) {
var stage = new $window.createjs.Stage(canvas);
}
I had a similar problem - in my case I added the createjs-module npm package for webpack (I use it in the Laravel wabpack mix). 我有一个类似的问题-在我的情况下,我为webpack添加了createjs-module npm软件包(我在Laravel wabpack混合中使用了它)。 It appeared that there was an issue with the scope, so I had to ensure that createjs is global. 似乎范围存在问题,因此我必须确保createjs是全局的。 So you can try to do the following: 因此,您可以尝试执行以下操作:
Install the npm module (in the console) 安装npm模块(在控制台中)
npm install createjs-module --save
Initialize the createjs (in your js file) 初始化createjs(在您的js文件中)
this.createjs = {};
Make createjs global (in your js file) 将createjs设置为全局(在您的js文件中)
window.createjs = this.createjs;
Import the module (in your js file) 导入模块(在您的js文件中)
require('createjs-module');
And now you can use it as usual :) 现在您可以照常使用它了:)
Reference: CreateJS GitHub Issues 参考: CreateJS GitHub问题
I just get some tests on it and i verify if the library EaselJS which is used for createjs is injected but it was not injected in the Bower.json file. 我只是对其进行了一些测试,并且验证了是否已注入用于createjs的库EaselJS,但未将其注入Bower.json文件中。 so i had to injected manually in the bower.json file and it's working. 所以我不得不手动将它们注入bower.json文件中,并且它正在工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.