angularjs - Angular: validating data via $http -


I have an angular instruction that allows users to enter genomic areas, as a line of data . Back-end railway and I want to validate the data against the backend.

Within my instructions, I have this function to verify

  Validate the functionGet (assembly, chrome, chrome_start, chrome_and) {$ http ({method : 'GET', url: '/ api / assemblies /' + assemblyid + '/ validate /', parameter: {chrom: 'chr' + chrom, chrom_start: chrom_start, Chrom_end: chrom_end}}) Success (data) {Console.log ("valid:" + data ['valid']); return data ['valid'];}); }   

When done independently, this work is fine, and returns either true or false . The user adds a target using the edit box, and then this code is

  scope.addRegion = function () {scope.onAddTarget ({chrom: (scope.coordinates.chrom || null) ), Chrome_start: (parseint (scope.cordinate.start) || null), chrome_and: (parseint (scope.cordinate.and) || null), validated: validated target (scope.Scidid, scope.cordinates.chrome) , Scope .corodents .start, scope.coordinates.end)}); Scope.coordinates = {}; }   

What is happening is valid that the time is set to clear when the addRegion function is called. Markup on the page displays all fields except valid , which is empty or zero (OT which is the correct JS term). Console validation shows the correct value of valid true / false from within the job.

I think the addRegion function can be completed by $ http , and at that point Valid is undefined / Taps happen.

I think there is a need to wrap it with some promise, but I'm losing a bit how to do it.

You need to use callback - Your code has been provided that you can do the following:

  Function references (assemblid, chrome, chrome_start, chrome_end, callback) {$ http ({method: 'GET', url: '/ api / assemblies /' + assemblyid + '/ valid / ', Parameter: {Chrome: CRR + Chrome, Chrome_start: Chrome_start, Chrome_and: Chrome_and}}) Success (Tasks (data) {console.log ("valid:" + data [' valid ']); Callback (data [ 'Valid']);}); } Scope.addRegion = function () {validateTargets (scope.assemblyid, scope.coordinates.chrom, scope.coordinates.start, scope.coordinates.end, function (results) {scope.onAddTarget ({chrom: (scope.coordinates. Chrom || null), chrom_start: (parseInt (scope.coordinates.start) || faucet), chrom_end: (parseInt (scope.coordinates.end) || null), valid: result}); scope.coordinates = {} ;}}}   

You have to pass a callback on the valid Goal so that you can use the response to your http call elsewhere .

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -