In my angular app coded in typescript, I am using ui grid to display some data in a bootstrap modal. What I want to achieve is that on click on any of the columns in a grid row modal closes. How can I make it happen? I am not using $modal or $modalInstance now, there is no need for this since it is a SPA. Is there a way to not use them and call modal.dismiss() onRowSelection?
You can use below code to open modal.
var modalInstance = $modal.open({
template: require('./modal.html'),
controller: require('./search.controller'),
controllerAs: 'searchModalInstance',
scope: $scope,
size: 'lg',
windowClass: 'search-modal-popup'
});
After that, add modalInstance scope into ui-grid appScopeProvider UI-Grid GridOptions
like, uiGridOption.appScopeProvider = modalInstance;
Now, you can close modal by calling function close() from ui-grid.
Related
I have a scenario where on click of the button I am triggering a modal with some information and social networking buttons in the modal footer.
When click on the social networking button i want the url which is sent should show a modal directly instead of showing the page
Route:
.state('main', {
url: '/main',
templateUrl: 'views/mainView.html',
controller: 'mainCtrl'
})
Controller:This is where i am opening a modal on button click
$scope.fnModal = function() {
var modalInstance = $uibModal.open({
animation: ISOURCE_TOGGLE.set,
backdrop: 'static',
templateUrl: 'views/modal/rescheduleModalView.html',
controller: 'ModalCtrl'
})
}
Modal ctrl: This is where the modal should be share on click of social share button using Socialshare service
$scope.socialShare = function() {
Socialshare.share({
'provider': 'facebook',
'attrs': {
'socialshareUrl': window.location.href
}
});
}
but here the main page is getting shared where as i want the modal should be shared directly
Any help would be appreciated.
Create a directive for modal.
Inject the directive in your controller and use it in html as follows.
<modal data-some-attr="value"></modal>
If your modal content is static, you can just add a query parameter in your URL when you open your modal (function $scope.fnModal) with this :
$state.transitionTo('main', {modal: 'true'}, { notify: false });
You don't change anything in your modal controller.
When an user comes to your page main, you have to check if in your url you have the query parameter modal sets to true. If yes, you open the modal or else just show the page without modal.
I have implemented a way for my controller to open a ui-bootstrap modal after a specific time. However if I navigate away from the page it will still open. The idea is for the modal to only open after a few minutes on that specific view. How do I stop it when a different controller loads? Thanks in advance. Please let me know if any other code is required.
Here is the code to open that modal:
$interval(function () {
var modalInstance = $uibModal.open({
animation: $scope.animationsEnabled,
templateUrl: 'modal.html',
controller: 'ModalInstanceCtrl',
size: 'lg',
});
}, 120000, [1]);
You might need to stop interval using $interval.cancel(your_interval) on route or state change please see this answer for "How to track route or state change?" and go through the $interval documentation $interval.cancel(). Hope this will solve your problem.
I am working on a timeout system for my angularjs app. On timeout I will be presenting the user with a timeout modal. The problem that I am having is with other modals that are already open, the timeout modal appears on top of the existing modal. I am looking for some suggestions on how I can close all the existing modals before opening the timeout modal. I am using the $modal service.
timeoutModal = $modal({
templateUrl: 'components/common/timeout.html',
controller: 'TimeoutController as time',
backdrop: 'static',
prefixEvent: 'timeoutMessage',
show: false
});
You can use
$modalStack.dismissAll();
usage
.controller("MyCtrl", function($scope, $modalStack){
// ...
$scope.closeAll = function(){
$modalStack.dismissAll();
};
)
My application has several 'modal' windows, For now there is no specific route to reach an open modal directly. I mean, written the url directly in the browser.
There are a Jquery solution, but how implement some similar solution for angular? where placed? when should run?
You can perform this sort of task within the routing config of your app.
For example, this one is using ui-router, for the routes, and ui-bootstrap for the modals.
In the route config add an onEnter which will fire when the route is first entered.
.state('login', {
onEnter: function ($stateParams, $state, $modal) {
$modal.open({
keyboard: false, // prevents escape-key closing modal
backdrop: 'static', // prevents closing modal outside of the modal
templateUrl: '/views/login', // view to load
controller: 'LoginCtrl' // controller to handle
})
}
})
Now, when navigating to the, in this example, login page the route will open the modal for me.
Using Angular Bootstrap UI I am opening a modal to allow the user to make some selections... from that modal the user can click on a help icon that would in turn open another modal. The second modal opens and displays perfectly, but I cannot trigger any functions from the second modal. I am trying to use ng-click for both the first and second modals.
I figured out what I was doing wrong... when I initiated the 2nd modal I wasn't passing in scope.
$scope.rptHelp = function() {
$modalInstance2 = $modal.open({
templateUrl: 'rptHelpModal.html',
scope: $scope //this line was missing
});
}