title: AngularJS passing a scope variable within a string to a directive
body: <p>I'm fairly new to AngularJS Directives and was wondering how I could implement passing a custom string, which is a url that contains a controller variable, to be used later on by that controller?</p>
  
  <p>Calling Directive</p>
  
  <pre><code>&lt;div ng-controller="MyController"&gt;
      &lt;my-custom-form after-submit="group/{{insertedId}}" /&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Directive</p>
  
  <pre><code>app.directive('myCustomForm', function() {
      return {
          templateUrl: 'myCustomForm.html',
          link: function(scope, element, attr) {
              scope.loadUrl = attr.afterSubmit;
          }
      }
  });
  </code></pre>
  
  <p>Controller</p>
  
  <pre><code>app.controller('MyController', function($scope, $location, $http) {
      $scope.loadUrl = '';
      $scope.insertedId = NULL;
      $http({
          method:'POST',
          url:'edit.php',   
          data:formData
      }).success(function(response) {
          $scope.insertedId = response.dbInsertedPrimaryId; // used in "after-submit"
          $location.path($scope.loadUrl); 
      });
  });
  </code></pre>
  
  <p>So when $location.path() called it sends me to a url for example:</p>
  
  <pre><code>http://example.com/group/22
  </code></pre>
  
  <p>The reason for this is so that I can pass a specific/different url each time the directive is used, like so </p>
  
  <pre><code>&lt;div ng-controller="MyController"&gt;
      &lt;my-custom-form after-submit="user/{{insertedId}}" /&gt;
      &lt;my-custom-form after-submit="home/{{insertedId}}/something" /&gt;
      &lt;my-custom-form after-submit="{{insertedId}}/anything" /&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Or maybe there is a better way to do this? I don't know that's why I'm asking. Thanks.</p>