我正在使用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
答案 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);
});
};
}]);