简体   繁体   English

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

[英]AngularJS NodeJS add $scope in external JavaScript file

I am using a controller controller.js that returns $scope.result = result; 我正在使用一个控制器controller.js返回$scope.result = result;

I have an other JavaScript file canvas.js and I would like to insert $scope.result data. 我还有另一个JavaScript文件canvas.js,我想插入$scope.result数据。

canvas.js : 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);

});

I have the following error: 我有以下错误:

Uncaught ReferenceError: $scope is not defined 

Try something along these lines in your HTML 在HTML中尝试以下方式

<canvas my-canvas coords={{result}}></canvas>

and then this directive 然后这个指令

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]
       }...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM