title: How can I add some small utility functions to my AngularJS application?
body: <p>I would like to add some utility functions to my AngularJS application. For example:</p>
  
  <pre><code>$scope.isNotString = function (str) {
      return (typeof str !== "string");
  }
  </code></pre>
  
  <p>Is the best way to do this to add them as a service? From what I have read I can do 
  this but then I would like to use these in my HTML pages so is it still possible if
  they are in a service? For example can I use the following:</p>
  
  <pre><code> &lt;button data-ng-click="doSomething()"
           data-ng-disabled="isNotString(abc)"&gt;Do Something
   &lt;/button&gt;
  </code></pre>
  
  <p>Can someone give me an example of how I could add these. Should I create a service
  or is there some other way of doing it. Most important I would like these utility
  functions in a file and not combined with another part of the main set up.</p>
  
  <p>I understand there's a few solutions but none of them are so clear.</p>
  
  <p><strong>Solution 1</strong> - Proposed by Urban</p>
  
  <pre><code>$scope.doSomething = ServiceName.functionName;
  </code></pre>
  
  <p>The problem here is I have 20 functions and ten controllers. If I did this it would mean adding a lot of code to each controller.</p>
  
  <p><strong>Solution 2</strong> - Proposed by me</p>
  
  <pre><code>    var factory = {
  
          Setup: function ($scope) {
  
              $scope.isNotString = function (str) {
                  return (typeof str !== "string");
              }
  </code></pre>
  
  <p>The disadvantage of this is that at the start of every controller I would have one or more of these Setup calls to each service which passed the $scope.</p>
  
  <p><strong>Solution 3</strong> - Proposed by Urban</p>
  
  <p>The solution proposed by urban of creating a generic service looks good. Here's my main set up:</p>
  
  <pre><code>var app = angular
      .module('app', ['ngAnimate', 'ui.router', 'admin', 'home', 'questions', 'ngResource', 'LocalStorageModule'])
      .config(['$locationProvider', '$sceProvider', '$stateProvider',
          function ($locationProvider, $sceProvider, $stateProvider) {
  
              $sceProvider.enabled(false);
              $locationProvider.html5Mode(true);
  </code></pre>
  
  <p>Should I add the generic service to this and how could I do it ?</p>