On my website, I have implemented a search bar that communicates with a controller receiving JSON responses from the server.
The response is stored in a global variable called assetResult
. It works as expected initially; however, subsequent searches do not update the $scope
of the searchResultController
.
SEARCH BAR CONTROLLER
mwm3.controller('searchBarCtrl', function($scope, $location, $timeout, AssetService) {
$scope.radioValue = 'id';
AssetService.connect();
AssetService.subscribe(function(message) {
var obj;
try {
obj = eval("(function(){return " + message + ";})()");
AssetResult = obj;
console.log(message);
$location.url('/searchResult');
} catch (e) {
obj = eval("(function(){return " + message + ";})()");
alert(obj.Error);
}
});
$scope.send = function() {
AssetService.send($scope.radioValue + '=' + $scope.searchKey);
};
});
SEARCH RESULT CONTROLLER
mwm3.controller('searchResultCtrl', function($scope, $location, AssetDetailService) {
$scope.$apply(function() {
$scope.asm = AssetResult;
});
if (!AssetResult) {
$location.url('/login');
}
});
In my searchResultController
, I've tried using $scope.apply
to refresh the associated view, but it doesn't seem to work. What could be causing this issue?
Any insights would be greatly appreciated. Thank you in advance!