I am new to AngularJS and I created a modal as described on http://angular-ui.github.io/bootstrap/ which opens on the click of a button. However, I also want it to open directly when the page loads, as some critical settings need to be entered in the modal. To this end, I directly call the open function when the controller is initialized and I was wondering whether this is a good or a bad practice, as I can't seem to find a better solution.
This is my Javascript code:
angular.module('myApp', ['ui.bootstrap'])
.controller('NavBarCtrl', ['$scope', '$modal', function($scope, $modal) {
$scope.openSettings = function() {
var settingsInstance = $modal.open({
templateUrl: 'settingsTemplate',
controller: 'SettingsInstanceCtrl',
scope: $scope
});
}
$scope.reset = function() {
alert('Not implemented yet');
};
$scope.openSettings();
}])
.controller('SettingsInstanceCtrl', ['$scope', '$modalInstance', function($scope, $modalInstance) {
$scope.closeSettings = function() {
$modalInstance.dismiss('closed');
}
$scope.saveSettings = function() {
//save
$modalInstance.dismiss('saved');
}
}]);
As you can see in the code, the closeSettings function of the controller's scope is immediately called when the $scope is set. Any feedback would be welcome.
Thanks a lot!