AngularJS NodeJS在外部JavaScript文件中添加$ scope

时间:2014-10-27 10:06:35

标签: javascript angularjs

我正在使用返回controller.js

的控制器$scope.result = result;

我有一个其他JavaScript文件canvas.js,我想插入$scope.result数据。

canvas.js

$(document).ready(function() {
    var d_canvas = document.getElementById('canvas');
    var context = d_canvas.getContext('2d');
    var background = document.getElementById('background');
    context.drawImage(background, 0, 0);


    context.rect(100, 50, 200, 20);
    context.rect(150, 205, 200, 20);
    context.lineWidth = 3;
    context.strokeStyle = 'green';
    context.stroke();

    // it doesn't display my data
    console.log("SCCOPE: "+$scope.idArticle);

});

我有以下错误:

Uncaught ReferenceError: $scope is not defined 

1 个答案:

答案 0 :(得分:0)

在HTML

中尝试这些内容
<canvas my-canvas coords={{result}}></canvas>

然后是这个指令

app.directive('myCanvas', function() {
   return {
     link: function(scope, elem, attrs) {
        var context = elem.getContext('2d');
        var background = document.getElementById('background');
         context.drawImage(background, 0, 0);
         [draw point at attrs.coords]
       }...