var arr = window.location.href.split("/"); if (arr[3].indexOf('app') == 0) baseUrl = ''; else baseUrl = '/' + arr[3]; angular.module('View.Directive') .directive('page', function () { return { restrict: 'E', templateUrl: baseUrl+'/Partials/templates-page', scope: { passedTotalPage: '=', passedCurrentPage: '=' }, link: function ($scope) { $scope.changePage = function (currentPage) { if (currentPage < 1 || currentPage > $scope.passedTotalPage) return; $scope.passedCurrentPage = currentPage; }; $scope.test = function (value) { return (value + $scope.passedCurrentPage) > 0 && (value + $scope.passedCurrentPage) <= $scope.passedTotalPage } $scope.$watch('passedTotalPage', function () { if (!$scope.passedCurrentPage) { $scope.passedCurrentPage = 1; } if ($scope.passedCurrentPage > $scope.passedTotalPage) { $scope.passedCurrentPage = $scope.passedTotalPage; } }); } } });