我在我的cordova应用程序中构建了一个app.js。在这个模块中有语音识别,如$ scope.recog。在这个功能我要赶使用switch语句一句话,这是我的代码:如何在Angularjs中使用Switch语句
$scope.recog = function() {
var recognition = new SpeechRecognition();
recognition.onresult = function(event) {
var result = event.results[0][0].transcript;
$scope.SwitchFuction = function (result){
switch(result){
case 'login':
$scope.loginFn();
break;
case 'sign up':
$location.path('/register');
break;
case 'register':
$scope.registerFn();
break;
case 'cancel':
$scope.cancelregisterFn();
break;
case 'go to home':
$location.path('/home');
break;
case 'go to add friend':
$location.path('/addfriend');
break;
case 'go to friend request':
$location.path('/friendrequest');
break;
case 'go to pending request':
$location.path('/penddingrequest');
break;
case 'add':
$scope.addfriends();
break;
case 'log out':
$scope.logout();
break;
}
};
$scope.$apply()
};
recognition.start();
};
的识别工作,但switch语句不工作我错写它还是有我错过了什么?感谢您的帮助
你在哪里调用'$ scope.SwitchFunction(结果);'? – jnthnjns
它的我的坏,对不起,我不应该使用该功能,谢谢 –
我建议你使用'ui路由'而不是开关案件。您可以阅读有关'ui-route'的文档:https://github.com/angular-ui/ui-router –