我的功能读取条形码后如何点击?

How to click after my function read a barcode?

我试图在我的应用程序读取条形码后点击搜索按钮,但到目前为止没有成功。

我的搜索按钮是$scope.buscar

$('#txtCode').val(imageData.text); 之后如何执行此操作?

条码控制

.controller("BarCode", function( $scope, $cordovaBarcodeScanner){
   $scope.scanBarcode = function(){    
         $cordovaBarcodeScanner.scan().then(function(imageData){
           $('#txtCode').val(imageData.text);

            }, function(error){
              console.log('Deu Merda'+error);
          });
    }
})

人员与语料库 Ctrl

.controller('PeopleCtrl',function($scope, $http) {
    $scope.people = [];

    angular.element(document).ready(function() {
        var httpRequest = $http({
            method: 'GET',
            url: 'json/clientes.json',
        }).success(function(data, status) {
            $scope.people = data;
        });

     });

})

.controller('CtrlCorpo',function($scope, $http) {
        $scope.people = [];

    angular.element(document).ready(function() {
        var httpRequest = $http({
            method: 'GET',
            url: 'json/clientes.json',
        }).success(function(data, status) {
            $scope.people = data;
        });

     });

搜索按钮

        $scope.buscar = function (){
            angular.forEach($scope.people, function(c, i) {
                var item = "<td><a href=cardapio.html?"+c.id+">"+ c.id + "</a></td>" + "<td>"+ c.name +"</td>"
                if(c.id == $('#txtCode').val()){
                    $('#tabelaPessoa').html(''),
                    $('#tabelaPessoa').append(item);
                }
            }
        );

        }
});

我必须搜索 JSON 所有客户端并开始显示我的应用程序。

当我单击我的 BarCodeScanner 按钮时,我将读取 ID 并自动搜索是否存在。在第二页自动进入'cardapio.html?clientid'。现在我正在尝试在阅读条形码后进行搜索。

您的问题是您试图访问控制器外部的范围。

My button is under the control of CtrlCorpo which in turn is under the control Barcode.

在 Angular 中,Parent 控制器无法修改 Child 控制器的数据。但是子控制器确实有访问权限,并且可以通过使用 $scope.$parent.varName 修改父控制器的范围变量。关于这个 Here 有一篇很棒的文章。

您正试图访问外部控制器内的作用域变量。查看我放在一起的示例,它复制了您遇到的问题。

var app = angular.module("MyApp", []);

app.controller("OuterCtrl", function($scope){
  $scope.myOuterCtrlVariable = "OuterCtrl";
});

app.controller("InnerCtrlOne", function($scope){
  $scope.ok = function(data){
     $scope.myOuterCtrlVariable = data;
  };
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app="MyApp">
  <div ng-controller="OuterCtrl">
    OUTSIDE: {{myOuterCtrlVariable}}

     <div ng-controller="InnerCtrlOne">
       INSIDE: {{myOuterCtrlVariable}}
       <button ng-click="ok('From Inner Ctrl')">OK</button>
     </div>
  </div>
</div>

要解决此问题,您可以 $broadcast 当您的 textfield 接收您需要的数据量以进行处理时的事件。该事件将向下传播 $scope 并击中 Button 所在的 ChildCtrl;然后你可以使用从上面传递给它的数据执行按钮(上面是父控制器)。

这里需要注意的是,使用 $broadcast 会将事件名称向下分配给所有子范围,而使用 $emit 则会向上分配事件名称。

阅读 here 了解有关 $emit$broadcast 的更多信息。

查看此示例,了解如何使用 $broadcast 完成此操作。

function firstCtrl($scope)
{
    $scope.$broadcast('someEvent', [1,2,3]);
}

function secondCtrl($scope)
{
    $scope.$on('someEvent', function(event, mass) { console.log(mass); });
}