【问题标题】:Angular and CreateJS not finding the stage elementAngular 和 CreateJS 找不到舞台元素
【发布时间】:2015-06-15 23:34:07
【问题描述】:

我有一个继承自 ng-view 元素的 Angular 视图。

在视图文件中,我有一个画布。代码由控制器控制。我想做的是调出一个舞台在画布上添加元素。

但是,当我运行 createJS.Stage 函数时,会创建一个舞台,其中所有内容都为 null 并且没有边界。

我猜元素没有绑定到舞台,但我不知道为什么

index.html

<ng-view     style='height: 100%;'></ng-view>

template.html

<div class='middle' style="min-height:90%;height:90%">
<div class='col-lg-8'>
<canvas id="demoCanvas" class='col-lg-11' style='margin-top:10px'></canvas>
</div>
</div>

JS

 app.controller('taskController',function($scope,$location,$routeParams,dataFactory){
    var stage = new createjs.Stage("demoCanvas");
    console.log(stage.getBounds()); 
   //bounds turn up as null as well as style and any other function that I run
}

【问题讨论】:

    标签: javascript angularjs easeljs createjs


    【解决方案1】:

    所以问题是当 AngularJS 控制器运行时 DOM 没有完全加载

    在 DOM 完成加载后运行它的技巧是

    app.controller('taskController',function($scope,$location,$routeParams,dataFactory){
        $timeout(function(){
            visualInspectionHandler();
        });
        function visualInspectionHandler(){
              var stage = new createjs.Stage("demoCanvas");
              console.log(stage.getBounds()); 
        }
    }
    

    【讨论】:

    • 如果您可以将 Canvas 作为创建的 HTML DOM 片段的一部分访问,您始终可以将其作为引用而不是 ID 传递(在 EaselJS 中仅使用 document.getElementById 查找)。这是我们通常在 Backbone 应用中采用的方法:new createjs.Stage(this.$(".demoCanvas").get(0));
    猜你喜欢
    • 2012-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-30
    • 2015-12-09
    • 2015-03-12
    • 2019-07-17
    相关资源
    最近更新 更多