var arr = window.location.href.split("/"); if (arr[3].indexOf('app') == 0) baseUrl = ''; else baseUrl = '/' + arr[3]; angular.module('View.Directive') .directive('commonSearch', function () { return { restrict: 'E', templateUrl: baseUrl+'/Partials/templates-common_search', scope: { passedFetchData: '&' // get fetch function from controller }, link: function ($scope) { $scope.searchText = ""; $scope.search = function () { $scope.passedFetchData({ searchText: $scope.searchText }); }; } }; });