Listening for UI changes - hovgaardgames/startupcompany GitHub Wiki
You can take advantage of Angular's watchers to listen for changes to the UI. In the below example we want to know if the player has opened the Feature Upgrade view.
GetRootScope().$watch('$root.view', (view) => {
if (view == 'product') {
setTimeout(() => { // Allow for angular to render
const productScope = angular.element('product *').scope();
productScope.$watch('ctrl.tab', tab => {
if (tab == 'features') {
setTimeout(() => { // Allow for angular to render
const featuresScope = angular.element('product-features *').scope();
featuresScope.$watch('featuresCtrl.selectedFeature', function (feature) {
console.log("The selected feature was changed, meaning we're inside the upgrade view.");
});
}, 50)
}
});
}, 50);
}
});