使用ng-webworker与应用程序不起作用

时间:2015-09-03 14:16:24

标签: javascript angularjs html5 web-worker

我正在使用ng-webworker构建一个应用程序,我使用ng-webworker构建了一个示例应用程序,并添加了所有必需的javascript。但它不起作用。

我需要在按钮点击时执行该功能。

代码:

 <md-button ng-click="callworker()">
                    CALL WEBWORKER
 </md-button>

JS:

var routerApp =angular.module('DiginRt', ['ngMaterial','ngWebworker'])
 routerApp.controller('AppCtrl', ['$scope',function($scope,Webworker) {
function doubler(num) {
    return num * 2;
}
var myWorker = Webworker.create(doubler);
$scope.callworker = function() {
  myWorker.run($scope.value).then(function(result) {
    alert("Answer: " + result);
});
}

以下是application

1 个答案:

答案 0 :(得分:1)

根据您的新代码链接,$scope.value未定义,您必须在$scope中定义;

var routerApp = angular.module('DiginRt', ['ngMaterial', 'ngWebworker'])
routerApp.controller('AppCtrl', ['$scope', 'Webworker', function ($scope, Webworker) {
    $scope.value = 10; //Added this.
    function doubler(num) {
        return num * 2;
    }

    var myWorker = Webworker.create(doubler);
    $scope.callworker = function () {
        myWorker.run($scope.value).then(function (result) {
            alert("Answer: " + result);
        });
    };
}]);