How to call a scope variable from a Javascript Angular Service

I created a Javascript Angular Service that is using the Barcodescanner plugin to generate a QR Code. So far, the service is working, but I need the encoded value to change depending on what is entered in an input field on the page.

So, I named the input field "value_to_encode" and mapped it via ng-model to a scope variable called "value_to_encode". Now I need to add the variable on the Javascript code.

This is the Javascript Angular Service code. The part I'm missing is where it says "NEED VALUE FROM SCOPE VARIABLE value_to_encode". I can generate the QR Code from this but I need the qrValue to come from the scope's "value_to_encode":

define(['require', 'lodash'],
function (require, _) {
return [{
type: 'service',
name: 'GenerateCode',
deps: ['Apperyio', encode]
function encode(Apperyio) {
return function(config) {
serviceSettings = Apperyio.EntityAPI("GenerateCode");
var qrValue = "NEED VALUE FROM SCOPE VARIABLE value_to_encode"; cordova.plugins.barcodeScanner.encode(cordova.plugins.barcodeScanner.Encode.TEXT_TYPE, qrValue, function(success) {
alert("encode success: " + success);
}, function(fail) {
alert("encoding failed: " + fail);

How to call a scope variable from a Javascript Angular Service?

1 person has
this question