[英]$scope Doesn't Apply Change To View After Async Call to Third Party API
I'm making an async call to a speech recognition API and try to store the result in a $scope variable, but the view doesn't change, even though the results show up in console.log
just fine. 我正在异步调用语音识别API,并尝试将结果存储在$ scope变量中,但是视图没有改变,即使结果显示在console.log
也很好。 I tried using $scope.$apply()
and $scope.applyAsync();
我尝试使用$scope.$apply()
和$scope.applyAsync();
as suggested in these threads - this and this , unfortunately with no effect 如这些主题中所建议- 此和此 ,不幸的是,没有任何效果
Here's what controller looks like: 这是控制器的外观:
myApp.controller('audiotest', function($scope)
{
$scope.recognize = function(){
speech.main('test.wav', function(err, res){
$scope.myResult = res.results[0].alternatives[0].transcript;
console.log($scope.myResult); // <- this logs correctly
$scope.$applyAsync(); // also tried with $scope.$apply();
});
};
};
I don't think the markup is relevant, but here it is, anyway: 我认为标记不相关,但无论如何,这里是:
<div class="row" ng-controller="audiotest">
<div class="row">
<button type="button" ng-click="recognize()"> Attempt recognition </button>
<p> Result is {{myResult}} </p>
</div>
</div>
Thanks in advance for any input or ideas. 在此先感谢您的任何意见或建议。
不确定,但是在声明识别功能之前,尝试在范围上初始化myResult。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.