Currently, I am working on enhancing my AngularJS application, where I have multiple widgets on a page displaying system status information. My goal is to allow users to hide the heading of a specific widget.
There is a 'Settings' button on the page that, when clicked, reveals a toolbar over each widget. This toolbar contains various buttons, including another 'Settings' button that opens a dialog for customizing widget settings.
In this dialog, I have included a checkbox that users can select to hide the widget's heading:
https://i.sstatic.net/exBhw.png
After selecting the checkbox and clicking 'Preview', I expect the widget heading to be concealed. However, I encounter an error message in the console that states:
TypeError: $scope.widget.toggleWidgetHeading is not a function
This error originates from the $scope.preview
function in ctrl.js, triggered by clicking the 'Preview' button in the dialog:
}).controller('WidgetPickerCtrl', function($scope, $timeout, fxTag, gPresets, appWidget) {
...
$scope.preview = function(e) {
$scope.widget.toggleWidgetHeading();
...
};
...
});
Although the function toggleWidgetHeading()
is clearly defined in directive.js, I am unsure why I receive this console error. Moreover, the 'Preview' button no longer closes the dialog.
Could the issue be related to the scope, considering I am calling the function from ctrl.js despite its definition in directive.js?