I'm new to Angular and encountering some issues with the watch function. I am trying to track changes in a variable inside a controller, and once the value of this variable changes, I want to pass that updated value to a directive.
Below is the code for the watch function:
$scope.$watch("comboDetail", function(newValue, oldValue) {
$scope.overlayProductCard = $scope.comboDetail.collectionCd;
console.log("$scope.overlayProductCardWithinWatch", $scope.overlayProductCard);
}
Here's a snippet of my directive code: (trimmed for better readability)
return {
scope: {
productCard: '='
},
restrict: 'E',
templateUrl: appVersionFactory.getViewBaseUrl() + '/assets/partials/tv/tv-overlay-link.html',
replace: true,
link: function($scope, iElm, iAttrs, controller) {
console.log("$scope.productCard", $scope.productCard);
};
However, when I try to access $scope.productCard
in the directive, it returns undefined. On the other hand,
$scope.overlayProductCardWithinWatch
gives me the correct data. How can I retrieve this data in the directive?