当我尝试这样做时,我收到以下错误
var fbcanvas = $('#fbcanvas');
这是我得到的错误
ReferenceError:$未定义
这是我的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 …Run Code Online (Sandbox Code Playgroud) 我有3个执行类似任务的控制器:
它们每个都是唯一的(尽管它们具有相似的功能)。但是,它们都从定义相同的$scope变量开始:
app.controller("PastController", function ($scope) {
$scope.Outages = "";
$scope.loading = 0;
$scope.nothing = 0;
$scope.error = 0;
//--- code continues ---//
});
app.controller("CurrentController", function ($scope) {
$scope.Outages = "";
$scope.loading = 0;
$scope.nothing = 0;
$scope.error = 0;
//--- code continues ---//
});
app.controller("FutureController", function ($scope) {
$scope.Outages = "";
$scope.loading = 0;
$scope.nothing = 0;
$scope.error = 0;
//--- code continues ---//
});
Run Code Online (Sandbox Code Playgroud)
我可以使用服务或工厂在一个地方初始化这些变量,而不用重复代码吗?