Q:

Directive controller function is not working

I am very new in angular js. I have an issue in directive. I have an ng-href from which I called the directive where in directive controller a function has written. I console the controller and it was working but the function on that is not working.
This is my config.js file:
 angular.module('movieApp').config(['$urlRouterProvider','$stateProvider', '$locationProvider', function($urlRouterProvider,$stateProvider,$locationProvider){
            $stateProvider.state('home',{
                url : '/home',
                templateUrl : 'app/components/home/home.html',
                controller : 'HomeController',
            }).state('yearsort',{
                url : '/yearsort/:id',
                template : '<year-sort></year-sort>',       
            });
            $urlRouterProvider.otherwise('home');
    }]);

This two links are there in my home page:
   <ul>
           <li><a ng-href="#/yearsort/oldtonew">Old to new</a></li> 
           <li><a ng-href="#/yearsort/newtoold">New to old</a></li>
      </ul>

This is my directive file:
  angular.module('movieApp.yearsort.directives', []).directive('yearSort',[function(){
    return{
    restrict : 'AEC',
        replace : true,
        transclude :  true,
        scope : {
             yearSortFn: '&'
        },
        controller : 'YearsortController',
        templateUrl : 'app/components/yearsort/yearsort.html',
    };
}]);

This is my YearsortController file where console.log('abc') is showing but the function is not working.
  angular.module('movieApp.yearsort.controller', []).controller('YearsortController', ['$scope','HomeFactory','$timeout','$state',function($scope,HomeFactory,$timeout,$state) {

    $scope.sortParam = $state.params.id;
        console.log('abc');

   $scope.yearSortFn = function(){
        HomeFactory.movieApiFn()
            .then(function(data){
                if($scope.sortParam=='oldtonew'&&$scope.sortParam!='newtoold'){
                    $scope.yearlyMovie = data.sort(function(a, b){return a.title_year - b.title_year});
                }
                else if($scope.sortParam=='newtoold'&&$scope.sortParam!='oldtonew'){
                    $scope.yearlyMovie = data.sort(function(a, b){return b.title_year - a.title_year});
                }
            },function(){
                console.log('data cannot retrieved');
            });
    } 

     <div ng-controller="YearsortController">
    <year-sort yearSortFn="yearSortFn()"></year-sort>
  </div>

This is my template file:
<div ng-controller="YearsortController">
        <div ng-repeat="movie in yearlyMovie track by $index" class="col-xs-10 col-sm-4 col-md-3 col-lg-3">
          <div class="panel panel-primary">
           <div class="panel-heading">{{movie.movie_title}}</div>               
          </div>
        </div>
     </div>
</div>

A:

Overall, from what you have provided, this is what I can come up with after reviewing things. That said, if this isn't helpful, please provide a demo for the community to better assist. At least explain what if anything is happening, errors or not.
You have an extra <div> tag:
<div ng-controller="YearsortController">
    <div ng-repeat="movie in yearlyMovie track by $index" class="col-xs-10 col-sm-4 col-md-3 col-lg-3">
        <div class="panel panel-primary">
            <div class="panel-heading">{{movie.movie_title}}</div>
        </div>
    </div>
</div>
</div> <!-- Remove this -->

Also, in your opening <div ...>, change it to simply <div>.
Also, what is this HTML snippet that is stuck under your controller code? I would remove that.
     <div ng-controller="YearsortController">
    <year-sort yearSortFn="yearSortFn()"></year-sort>
  </div>

And thus, remove this as well (you aren't using it):
scope : {
     yearSortFn: '&'
},

