Question: I created an angular `Value` service that holds a regex than I attached it to the controller instance i.e.

```
myService.value('regexValue' {PASSWORD_REGEX: /passwordregex/})

```

```
myController(regexValue) { 
    this.regexValue = regexValue.PASSWORD_REGEX;  
}

```

then I am trying to use this value in an input field `data-ng-pattern` attribute 

`<input type="password" data-ng-pattern="myController.regexValue.PASSWORD_REGEX">`

this however does not seem to work with the ng-pattern directive.

**My question is how can I get this to work?**

Answer: 
Your theory is correct. `ng-pattern` accepts both a string representation of a pattern, an inline pattern or a scoped variable. The only problem is that you are scoping regexValue.PASSWORD\_REGEX under the controller as controller.regexValue, and then thrying to access controller.regexValue.PASSWORD\_REGEX.

Either do:

```
myController(regexValue) { 

    this.regexValue = regexValue.PASSWORD_REGEX;  
}

<input type="password" data-ng-pattern="myController.regexValue">

```

or 

```
myController(regexValue) { 
    this.regexValue = regexValue;  
}

<input type="password" data-ng-pattern="myController.regexValue.PASSWORD_REGEX">

```

Working fiddle: <http://jsfiddle.net/yrq18bbh/3/>
ng-pattern wants a string representation of the pattern (without the /), so you can get that from your regex by accessing the `source` property:

```
<input type="password" data-ng-pattern="myController.regexValue.PASSWORD_REGEX.source">

```

```js
console.log(/foo+bar*?/.source)
```