title: AngularJS dynamic sort function with parameters
body: <p>Based on <a href="https://stackoverflow.com/questions/29635796/dynamic-orderby-in-angularjs">Dynamic orderBy in AngularJS</a> I try to implement a dynamic sort function with parameters. It's not working properly because the default sort is being called. How can I make it not calling the default sort by name?</p>
  
  <p>I have 2 buttons to call the function and send the parameter.</p>
  
  <pre><code>&lt;button ng-click="dynamicOrder('f9.id')" class="btn"&gt;Sort by rating&lt;/button&gt;            
  &lt;button ng-click="dynamicOrder('name')" class="btn"&gt;Sort alphabetic&lt;/button&gt;
  </code></pre>
  
  <p>My ng-repeat looks like this:</p>
  
  <pre><code>&lt;li ng-repeat="item in cumulus.items | orderBy: dynamicOrder()"
      ng-show="cumulus.items.length &gt; 0" class="block-grid-item"&gt;
      &lt;p&gt;
          &lt;a target="_blank" href="{{ item.image }}"&gt;
              &lt;img class="img-responsive" src="{{ item.thumb }}"&gt;
          &lt;/a&gt;
      &lt;/p&gt;
      &lt;p style="overflow: hidden;"&gt;{{ item.name }}&lt;/p&gt;                    
      &lt;p class="text-primary"&gt;&lt;input type="hidden" value="{{ item.f9.id }}" /&gt; {{ item.f9.displaystring }}&lt;/p&gt;
  &lt;/li&gt;
  </code></pre>
  
  <p>and my function for order</p>
  
  <pre><code>$scope.dynamicOrder = function (sortParam) {
      if (!sortParam) {            
          return 'name';
      } else {
          console.log("sortParam: ", typeof (sortParam), sortParam);
          return sortParam;
      }  
  };
  </code></pre>