I am trying to make a search function in AngularJS. Here is my code for controllers:
app.controller('SearchController',['$scope', '$window','SearchService', '$cookies' ,'$location','$routeParams',
function($scope,$window, SearchService, $cookies, $location, $routeParams) {
$scope.homePageSearch = function(search) {
$scope.result = '';
$scope.count = '';
SearchService.setSearchData(search);
$window.location.href = '/search/';
}
$scope.jobDetail = function(){
var slug = $location.absUrl().split('/')[4];
SearchService.getJobDetail(slug).then(function(data){
console.log(data)
});
}
var url = $location.absUrl().split('/')[3];
if(url == 'jobdetail'){
$scope.jobDetail();
}
});
}]);
I am calling homePageSearch function on page load. After this I am redirecting the page to /jobDetail/ and calling function jobDetail.But the problem is homePageSearch() function is also called on jobDetail page How can I avoid calling homePageSearch() function on jobDetail Page.
Shall I use a different controller for /jobDetail/ page?
I am new to angularJs please suggest me proper way to achieve this.