我创建了一个函数,它结合了另外两个可以单独触发的函数(recorder.start()和recorder.stop())。当我尝试在一次点击中添加这些功能时,程序一次只能触发一个功能。如果程序要启动第二个功能,我不得不再次按下按钮。按下按钮后可以启动两个功能吗?
的JavaScript
$scope.record = function() {
recorder.start($scope.recordConfig).then(function() {
var test = $scope.recordConfig.captureSource;
recorder.stop();
})
},
n.start = function(e) {
return t.postMessage("start", e)
},
n.stop = function() {
t.postMessage("stop")
},
c.postMessage = function(e, t) {
return c.getPort().then(function(n) {
return n.postMessage({
type: e,
data: t
})
})
},
HTML
<md-button ng-click="record()" class="md-primary md-raised">Start Recording</md-button>
=============================================== ========================
popup.html.js
$scope.recordStart = function() {
// recorder is an angular module which can postMessage such as start/stop/pause... ...
recorder.start($scope.recordConfig)
.then(function() {
var test = $scope.recordConfig.captureSource;
"tab" !== test && "desktop" !== test || a.IS_E2E;
})
$scope.stop = function() {
recorder.stop();
},
$scope.record = function() {
$scope.recordStart();
$timeout(function(){$scope.stop(); },4000)
}
答案 0 :(得分:0)
对于函数,第二个参数是您已应用的回调,但如果仔细检查,您会发现您还注入了第三个参数并将其视为回调函数。您可以通过在其他函数中调用一个函数来轻松完成此操作。
<强>例如强>
$scope.ParentFunction=function(){
$scope.child_sibling1();
}
$scope.child_sibling1=function(){
$scope.child_sibling2();
}
$scope.child_sibling2=function(){
//your code
}
答案 1 :(得分:0)
此示例向您展示如何使用$ timeOut
一键调用两个函数In&#34; CallFun&#34;我们手动使用$ timeout,调用&#34; fun2()&#34; 2秒后
你也可以通过调用API来做到这一点。
var app = angular.module("app", [])
app.controller("ctrl", function($scope, $timeout){
$scope.fun1 = function(){
$scope.message = "Return function 1"
}
$scope.fun2 = function(){
$scope.message = "Return function 2"
}
///this is manually timeout
$scope.callFun = function(){
$scope.fun1();
$timeout(function() {
$scope.fun2();
}, 2000);
}
});
&#13;
<html>
<head></head>
<body ng-app="app" ng-controller="ctrl">
<button ng-click="callFun()">call functions with $timeout</button>
{{message}}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
</body>
</html>
&#13;