After creating a search bar that triggers an event upon completion of the search, I set up a listener in the form of a controller to handle the data passed from the search bar. This data is then bound to the view using {{ controller.node.name }}
.
app.controller('Controller', function($rootScope){
this.node = undefined;
$rootScope.$on('searchEvent', function(event, info) {
$timeout(function(){
$rootScope.$apply(function(){
set(info);
});
}, 0);
});
function set(c) {
this.node = c;
}
});
I came across solutions involving $scope.$apply
, but they primarily use $scope.node
instead of my approach using controller.attribute
.
When I tried using $scope.node
, it worked perfectly fine. So my question is, why isn't it working with a controller attribute?