Question: I'm trying to use the [fingerprintjs2](https://github.com/Valve/fingerprintjs2) javascript library, to get browser fingerprints.

The following code works ok:

```
new Fingerprint2().get(function (result) {
    var output = result;
    document.write(output);
});

```

However, I would like to set a variable outside of this block, to be used later e.g.:

```
var output;

new Fingerprint2().get(function (result) {
    output = result;
});

document.write(output);

```

but in this case I get the output:

```
undefined

```

I'm guessing this is related to scope, so is there any way to set the variable in the outer scope, or do I need to put all following code inside this function call?

I've read other questions about getting the value of nested functions, but none seem to work in this case.

Answer: 
If you're using bootstrap UI, you can add it as a `resolve` entry:

```
yourItems = [...];

$uibModal.open({
  ...
  controller: 'MyModalCtrl as modal',
  resolve: {
    modalItems: function() {
      return yourItems;
    }
  }
})

```

And inject it into your controller like so:

```
angular.module('myApp').controller('MyModalCtrl', function(yourItems) {
    ...
});

```
I'm not exactly sure how you're project is set up, but there are two libraries that I recommend for creating modals easily.

[ngDialog](https://github.com/likeastore/ngDialog) and [ui-bootstrap](https://angular-ui.github.io/bootstrap/)

Both of these have simple methods for attaching data and controllers to dialogs as well as creating your own templates and styles for them.