title: Include 3rd-party Javascript Libraries into an AngularJS app
body: <p>I'm trying to include a javascript libraries (actually, a handfull) into my AngularJS app. So far, I am building a stripped down version of this app, with no design. It's just all about functionality and data processing at this point.</p>
  
  <p>This is the first javascript library I'm attempting to add into my AngularJS app: <a href="https://github.com/LarryBattle/Ratio.js">https://github.com/LarryBattle/Ratio.js</a></p>
  
  <p>At first, I tried to simply include it into my HTML file using script src tag, but when I try to use it inside my controller, I receive this error: <em>ReferenceError: require is not defined</em></p>
  
  <p>I've read that it's best to convert javascript libraries into services or directives or even filters when using AngularJS. Can anyone provide any insight on the best way to do this? Or perhaps some relevant tutorials? I have not been able to find one that is simple enough to apply to my needs. Can anyone help or provide some direction with this? Here's my code so far:</p>
  
  <pre><code>&lt;html ng-app="myApp"&gt;
  &lt;head&gt;
      &lt;title&gt;PercentCalc App&lt;/title&gt;
  &lt;/head&gt;
  &lt;body ng-controller="MainCtrl"&gt;
  
  Amount: &lt;input type="number" ng-init="amountone=28" ng-model="amountone"&gt; Value: &lt;input type="number" ng-init="valueone=300" ng-model="valueone"&gt;
  &lt;br /&gt;
  Amount: &lt;input type="number" ng-init="amounttwo=3.5" ng-model="amounttwo"&gt; Value: &lt;input type="number" ng-init="valuetwo=50" ng-model="valuetwo"&gt;
  &lt;br /&gt;&lt;br /&gt;
  =========================
  &lt;br /&gt;&lt;br /&gt;
  Test ratio: {{ amountone }}/{{ amounttwo}} = {{ ratioone() }} OR {{ ratioonestring }}&lt;br /&gt;
  Test ratio: {{ amounttwo }}/{{ amountone}} = {{ ratiotwo() }}&lt;br /&gt;
  
  &lt;script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="js/ratio.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="js/percentcalc-ng-one.js"&gt;&lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>===</p>
  
  <pre><code>//percentcalc-ng-one.js
  'use strict';
  
  var app = angular.module('myApp', []);
  
  app.controller('MainCtrl', function ($scope) {
      console.log($scope);
      var Ratio = require("lb-ratio"); // &lt;--- this is where the error is thrown
      $scope.ratioone = function () { return $scope.amountone / $scope.amounttwo; }
      $scope.ratiotwo = function () { return $scope.amounttwo / $scope.amountone; }
  
      $scope.ratioonestring = Ratio.parse( $scope.ratioone() ).simplify().toString();
  
  });
  </code></pre>
  
  <p>I would really be appreciative if anyone could help direct me on how to include 3rd-party javascript libraries into my AngularJS app. I'd like to be able to add it as a dependency into certain apps, that way I could reuse this feature in other apps. Thanks in advance!</p>