Question: I have a longer jQuery function for an image gallery slider. I have about 5 directives (all using he same slider with different pictures). As I didn't want to copy paste the same jQuery code into all 5 controllers, I did it using a factory.
I put the jQuery code into a factory, then called the factory in each controller. Its not working but I can't see why. Does anyone know?Thank you!
EDIT: Jquery is included bevor angular and works! The problem is not jQuery itself but the factory. If I use the same jQuery code over and over again in all controllers, its working. Its not working if i put it in the factory and can the factory in controllers.
Factory:

```
app.factory('prodsFactory', function ($http) {
  var prodsFactory = {};
    prodsFactory.slider=function(){
       $(function(){
           ...
        })
     }
 })

```

1st directive:

```
app.directive('picturesProject', function () {
    return {
        restrict: 'E',
        templateUrl: 'projects/shop/picturesshop.html',
        scope: {},
        controller: 'shopCtrl',
        link: function(scope){
        }
 }

})

app.controller('shopCtrl', function($scope,prodsFactory){
        return prodsFactory.slider();
});

```

index.html
...

```
<script src="projects/shop/picturesshop.directive.js"></script>

```

...

Answer: 
**tl;dr**

Gmail and certain other clients don't like `base64` encoded images.

**Full Story**

The very first thing I did was view "Show Original" in Gmail. To my surprise, raw content still has your embedded image data:

[![enter image description here](https://i.stack.imgur.com/87xTG.png)](https://i.stack.imgur.com/87xTG.png)

That tells me right away that gmail is simply choosing to filter this content out. I was not able to find the reason. Some guesses point out the [length of encoded data itself](https://productforums.google.com/forum/#!msg/gmail/TJ50pIxRVPQ/1Kr5-vHmfwMJ). Others talk about the general way in which [Gmail filters out images](https://github.com/gitlabhq/gitlabhq/issues/9063). There are even records of this technique [functioning a number of years back](https://stackoverflow.com/questions/3279523/base64-images-to-gmail).

In addition, when viewing the same exact email in a third party client such as Newton(formerly Cloud Magic), I do see images properly rendered.

[![enter image description here](https://i.stack.imgur.com/tmbFp.png)](https://i.stack.imgur.com/tmbFp.png)

All of that points to a simple, however sad, fact that gmail doesn't like inline encoded images. Not in the browser and not in their mobile apps.

In fact, at the very end I did discover a post from [2013 by Campaign Monitor blog](https://www.campaignmonitor.com/blog/email-marketing/2013/02/embedded-images-in-html-email/) that concludes with the same results.

Don't use inline embedded images.
Are you using nodemailer?

If yes, there is the solution!

NPM has a package called [nodemailer-plugin-inline-base64](https://www.npmjs.com/package/nodemailer-plugin-inline-base64) that allow you to send an image with data uri to all emails providers like gmail, outlook, an others.

Setup:

```
yarn add nodemailer nodemailer-plugin-inline-base64

```

And try it out

```js
var nodemailer = require('nodemailer');
var inlineBase64 = require('nodemailer-plugin-inline-base64');
transporter.use('compile', inlineBase64({cidPrefix: 'somePrefix_'}));
transporter.sendMail({
    from: 'me@example.com',
    to: 'hello@mixmax.com',
    html: '&lt;img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAlgAAAACCAYAAACE7KJkAAAAI0lEQVRYR+3DMQ0AAAgDsKlFzZxgEhOcbdIEAIBf7Y6qqn8P0MMQZPno7TMAAAAASUVORK5CYII=">'
});

```

Have a nice day!