Javascript AngularJS - ReferenceError: $ 未定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30773161/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 05:42:54  来源:igfitidea点击:

AngularJS - ReferenceError: $ is not defined

javascriptangularjscanvasreference

提问by Demian

I'm getting the following error when I try to do this

尝试执行此操作时出现以下错误

var fbcanvas = $('#fbcanvas');

var fbcanvas = $('#fbcanvas');

This is the error I got

这是我得到的错误

ReferenceError: $ is not defined

参考错误:$ 未定义

This is my JS code

这是我的JS代码

var feedbackModule = angular.module('feedbackModule', [ 'ui.bootstrap', 'dialogs' ]);

feedbackModule.controller('feedbackDialog', function($scope, $rootScope, $timeout, $dialogs) {
$scope.confirmed = 'You have yet to be confirmed!';
$scope.name = '"Your name here."';

$scope.sendFeedback = function() {

html2canvas(document.body, {
    onrendered: function(canvas) {
    var data = canvas.toDataURL('image/png'), dlg = null;

    dlg = $dialogs.create('js/plugin/vzfeedbacktool.html', 'feedbackToolController', {
        imgdata: data
    }, {
        key: false,
        back: 'static'
    });
    dlg.result.then(function(name) {
        $scope.name = name;
    }, function() {
        $scope.name = 'You decided not to enter in your name, that makes me sad.';
    });

    }
});
}; // end launch

});

feedbackModule.controller('feedbackToolController', ['$scope', '$modalInstance', function($scope, $modalInstance, data) {

$scope.cancel = function() {
$modalInstance.dismiss('canceled');
}; // end cancel

$scope.save = function() {
debugger;
var fbcanvas = $('#fbcanvas');
var ctx = fbcanvas.getContext('2d');
var image = new Image();

image.src = data.imgdata;
ctx.drawImage(image, 0, 0);
}; // end save

}]);

Any idea if I'm missing something? by the way, if I try to execute that code directly in the console it works fine :S

知道我是否遗漏了什么吗?顺便说一句,如果我尝试直接在控制台中执行该代码,它可以正常工作:S

Thanks

谢谢

采纳答案by Martin Zarate Rafael

Try this:

尝试这个:

var fbcanvas = document.getElementById('fbcanvas');

instead of:

代替:

var fbcanvas = $('#fbcanvas');

Check if data is undefinedtoo.

检查数据是否undefined也是。