In the controller, there is HTML button code that attempts to call a specific function on click:
<button ng-click="vm.openpopup()" ng-if="!vm.data.length"
uib-tooltip="Add Business Value Chain"
class="btn btn-default `enter code here`ti-form-action-btn" id="add-bvc-btn">
<em class="glyphicon glyphicon-plus-sign"></em>
Add
</button>
function openpopup() {
$scope.$broadcast('popup');
}
Within the same controller, there is a broadcast listener code located in a component:
$scope.$on('popup', function () {
openModalPopup();
});
The button only appears when there is no data available.
The function call works correctly, but the broadcast event only triggers once if data exists and is manually deleted. However, if there is no data present upon page load, the broadcast event does not trigger.
Attempts to use $rootScope.broadcast
and enclosing the code block within $timeout
have not produced any results.
This involves communication between the controller and component using broadcast events. How can this be properly handled during page load?