I have used a controller in angularjs in the same page in two different divs:
One div is a filter like thing:
<div class="upload_date mar_btm" ng-controller="recentuploadsController">
<ul>
<li><a onclick="filterTopSearch(1)">Today</a></li>
<li><a href="javascript:void(0);" ng-click="getTimely(7)">Last 7 Days</a></li>
<li><a href="javascript:void(0);" ng-click="getTimely(30)">Last 30 Days</a></li>
<li><a href="javascript:void(0);" ng-click="getTimely(365)">Last 12 Months</a></li>
<li><a href="javascript:void(0);" ng-click="getTimely(0)">All Time</a></li>
</ul>
</div>
Other one is the actual dive where it should update :
<div class="recent_uploads mar_btm" ng-controller="recentuploadsController">
<div class="mar_btm titl_img"><h6>Recent Uploads</h6><!--<img alt="recent uploads" src="<?php echo base_url(); ?>public/image/net03.png">--></div>
<input type="text" ng-model="search.text" class="community-searching hide">
<button ng-click="clearSearch()" class="hide">clear</button>
<div class="rec_uplist_cont">
<div class="rec_uplist_slider">
<div class="flex-viewport" style="overflow: hidden; position: relative;">
<ul class="slides" style="width: 800%; transition-duration: 0.6s; transform: translate3d(-240px, 0px, 0px);">
<div class="recnt_info" ng-if="recentupload!=null"><p> No Data Found</p></div>
<li id="apptest" style="width: 226px; float: left; display: block;" class="animate-repeat" ng-repeat="recentupload in recentuploads | filter:search.text">
</li>
</ul>
</div>
<ol class="flex-control-nav flex-control-paging"><li><a class="">1</a></li><li><a class="flex-active">2</a></li></ol><ul class="flex-direction-nav"><li><a href="#" class="flex-next">Next</a></li><li><a href="#" class="flex-prev">Previous</a></li></ul></div>
</div>
</div>
And here's the AngularJS controller:
app.controller('recentuploadsController', function ($scope, $http) {
// console.log("Angular in role now");
/**
* Get list of all hashtags realtime
*/
$scope.getTimely = function(day) {
//alert('here');
$scope.days = day;
$http.get(base_url + 'getAllUsers/getRecentUploads?key='+day).success(function(data, status, headers, config)
{
$scope.recentuploads= data;
$scope.search = {text:null};
$scope.clearSearch = function () {
$scope.search={text:null};
}
$scope.loadTrendingStuff = function(hashtag) {
// get single hashtag id
$scope.hashtag=hashtag
}
console.log(data);
$scope.$apply(function() {
$rootScope.data = data;
});
});
}
$http.get(base_url + 'landing/getRecentUploads').
success(function(data, status, headers, config) {
// this callback will be called asynchronously
$scope.recentuploads = data;
$scope.search = {text:null};
$scope.clearSearch = function () {
$scope.search={text:null};
}
$scope.loadTrendingStuff = function(hashtag) {
// get single hashtag id
$scope.hashtag=hashtag
}
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
});
I would like to know where am I wrong? The data is posted from the backend and is logged to the console well. But the view is not updated. Why is that? Is it that two instances of same controller are created when I use it twice in my application (as I read while researching). Please answer. Thanks!