Friday, 15 June 2012

javascript - How to click after my function read a barcode? -


My app has read a barcode, after which I'm trying to click on the search button, but so far Without success

My search button $ scope.buscar

How can I do it after the $ ('# txtCode')? Val (imageData.text); ?

Barcode Ctrl

  .controller ("barcode", function ($ radius, $ cordova barcode escanner) {$ scope .scanBarcode = function () { $ CordovaBarcodeScanner.scan ()} Then (function (image data) {$ ('# txtCode'). Val (imageData.text);}, function (error) {console.log ('Deu Merda' + error);}) ;}})  

People & amp; Corp. Ctrl

 . Controller ('logon', function ($ radius, $ http) {$ scope.people = []; angular.lement (document) .ready (function () {var httpRequest = $ http ({method: 'GET', url : 'Json / clients.json',} Success (work (data, position) {$ scope.people = data;}}}};}). Controller ('CtrlCorpo', function ($ radius, $ http) { $ Scope.people = []; angular element (document) .ready (function () {var httpRequest = $ http ({method: success (function (data, position) {$ scope.people = data;});} );  

strong> search button

  $ scope.buscar = function (angular.forEach ($ scope) .people, function (c, i) {var item = "& lt; td> & lt; a href = cardapio.html?" + Cid + "& gt; + + c.id +"  & lt; / td> "+" & lt; td & gt; "+ c.name +" & Lt; / td & gt; "if (c.id == $ ('# txtCode'). Val ()) {$ ('# tabelaPessoa'). Html (''), $ ('# tabelaPessoa'). Attachment (item);}});}});  

I have to search for all the clients in JSON and show my app.

When I click on my barcode sens button, I read the ID and automatically find me and if present. Automatic second page 'cardapio.html? Clientid 'for now I'm trying to search after reading the barcode.

Your problem is that you use a scope outside your controller

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

In the corner parent the controller can not modify the data of a child controller. But a child controller is used, and $ scope. Using parental.varName can modify parental scope variable. There is a great article on this

You are trying to reach a scope variable inside the external controller. Look at this example that I have put together which replicates your problem.

  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;};});  
  & lt; Script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js" & gt; & Lt; / Script & gt; & Lt; Div ng-app = "MyApp" & gt; & Lt; Div ng-controller = "OuterCtrl" & gt; Outside: {{myOuterCtrlVariable}} & lt; Div ng-controller = "infiniteom" & gt; Inside: {{myOuterCtrlVariable}} & lt; Button ng-click = "OK ('from inner' Ctrl ')" & gt; OK & lt; / Button & gt; & Lt; / Div & gt; & Lt; / Div & gt;  

To fix this, you can $ broadcast make an event when your Textfield takes the amount of data according to your process requirement; This program will broadcast below the $ range and press ChildCtrl where The button remains ; You can execute the button above (above the original controller) with the above data.

Keep in mind that $ broadcast send the name of an event using $ emit to go all hair scope downwards Will happen.

For more information, $ emit versus $ broadcast .

See this example how this can be accomplished by $ broadcast .

  function firstCtrl ($ scope) {$ radius $ Broadcast ('some event', [1,2,3]); } Function secondCtrl ($ scope) {$ scope. $ ('SomeEvent', function (event, mass) {console.log (mass);}); }  

No comments:

Post a Comment