title: Convert Grails GSP custom tag to AngularJS directive
body: <p>Converting from Grails / GSP custom tag to AngularJS Directive</p>
  
  <p>I have an existing Grails / GSP tag lib that will generate a link that will be displayed by a remote server, loading content from the local server. The URL in the link must be the full path. The custom GSP tag lets me specify the action right in the GSP. I need to replace this using AngularJS, and I understand that directives are the way to go.  Is there an easy way to pass parameters from
  the tag in a GSP into the directive? </p>
  
  <p>Are there equivalent functions to the "grailsLinkGenerator" that I can use to generate the URL inside the directive?</p>
  
  <p>My existing Grails / GSP tag looks something like this:</p>
  
  <p>GSP:</p>
  
  <pre><code>&lt;g:myRemoteLink action="alpha" update="targetDiv" id="${ent.id}" &gt;Show Alpha&lt;/g:myRemoteLink&gt;
  </code></pre>
  
  <p>MyTagLib.groovy:</p>
  
  <pre><code>def myRemoteLink = { attrs, body -&gt;
    def link = g.remoteLink( attrs, body )
    def fullLink = link.replace( grailsLinkGenerator.contextPath, grailsLinkGenerator.serverBaseURL )
    out &lt;&lt; fullLink.toString()
  }
  </code></pre>
  
  <hr>
  
  <p>I need to convert it over to load/display the remote content in a ng-switch like this:</p>
  
  <pre><code>&lt;div ng-switch-when='alpha' &gt;&lt;div alpha-directive&gt;&lt;/div&gt;&lt;/div&gt;
  </code></pre>
  
  <p>So far I came up with this directive, but there must be a better way? Is there something like the grails link generator in AngularJS? I still need to pass in the ID to be appended to the URL.</p>
  
  <pre><code>app.directive('alphaDirective', function() {
    var id = $scope.id;
    var baseURL = "https://myServerURL/";
    var controller = "admin";
    var action = "alpha";
    var path = "'" + baseURL + "/" + controller + "/" + action + "/" + id + "'";
    return {
      template: "&lt;div ng-include=\"" + path + "\"&gt;&lt;/div&gt;"
    };
  });
  </code></pre>