我正在使用返回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
答案 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]
}...