Javascript - angular passing a variable from a controller to a function in a service not working
<p>I am pretty new to javascript and angular so this question is quit a newbee question. I am trying to pass a variable from my controller to a service and then use it in my function, but when I do the console.log I don't get the variable. This is my controller:</p>

<pre><code>var message = "Some error message.";
ErrorService.alertMessage(message);
</code></pre>

<p>And my factory:</p>

<pre><code>.factory('ErrorService', function() {
  return {
    alertMessage: function(message) {
      document.addEventListener("deviceready", onDeviceReady, false);

console.log(message);

      function onDeviceReady(message) {

        console.log(message);

        if (navigator.notification &amp;&amp; navigator.notification.alert) {
          navigator.notification.alert(
            message,   // the message
            function() {},                      // a callback
            "Error",                            // a title
            "OK"                                // the button text
          );
        } else {
          alert(message);
        }
      }
    }
  };
});
</code></pre>

<p>The first <code>console.log</code> gives me the variable value, but the second <code>console.log</code> inside <code>onDeviceReady</code> function doesn't output anything.</p>