javascript - Properties of object returned by service not available -


I have a web page where a user can register for the account. I have given a simple directive that checks that the username has already been taken, and if so, then it should invalidate the form field.

My command calls a PHP webservice that checks the database and status of a JSON object that username

My command just looks like this:

  link: function (scope, elm, etters, c) {alm.bind ('blur', function) {var Results = accountService.uniqueUser (elm.val ()); Console.log (results); Console.log ('A:' + result.usernameIsTaken);}}};  

As you can see I do two console.logs . The first one gives it:

  resources {$ promise: object, $ solution: wrong, $ get: function, $ save: function, $ query: function ...} $ promise: Object $ solution: True username: Ticken: wrong __proto__: resource  

So as you can see that the "property" contains userNameIsTaken but when the second console.log triggers when it is triggered:

  A: undefined  

Why can not I use U Properties? Why is it giving me undefined when the first console.log clearly shows that it should be ...?

Is there anything that I am missing here?

Your problem is that you are making an asynchronous request on the server, but hopefully the result is immediately Will be available.

Instead, you can pass successful callback to resource on the $ promise object to handle data available:

  results. $ Promise Then (function (data) {console.log (data.usernameIsTaken);});  

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -