ivaynberg/select2 — pull request #1731 by Selmanh (2013-09-18 01:50:38+00:00)
Title: added if condition to formatNoMatches func

- if no matches found message is string, just render it, otherwise pass it to render function as an object

The reason I did is that I was using ui-select2 for AngularJS. I wanted to place a button when there is no results for the search. It looks like this:

![image](https://f.cloud.github.com/assets/3432700/1162130/c276ab68-2003-11e3-8af2-da7512e37577.png)

Here is the no matches found string I was passing to formatNoMatches function:

```javascript
var msg = '

No matches found. Invite!

';
```

Problem here is that when user clicks on invite button, it doesnt call Angular function inviteUser, because we didn't compile it. After I compile this html using:

```javascript
return $compile(msg)($scope);
```

it returns me javascript object. And when I pass this object to render function;

```javascript
render("
" + opts.formatNoMatches(search.val()) + "
");
```

here is the output:

```
[object object]

```

To avoid this, I put if-else statement. If it is object, don't include li tags, otherwise use it as a string.

There is this directive to allow us use this library in AngularJS
https://github.com/angular-ui/ui-select2

But I couldn't have time to modify it to fix this problem. Please let me know if there is simple way to achieve this.

Thanks.