Close ,opened particular modal on page loads in angular-ui bootstrap - javascript

i have a code in routing like this
.state('resetPassword', {
url: '/home/reset_password',
templateUrl: 'home/home.html',
controller: 'HomeController',
controllerAs: 'vm',
data: {
requireLogin: false /* This is what tells it to require authentication */
},
onEnter: function($state, $uibModal) {
var mymodal=$uibModal.open({
backdrop: true,
templateUrl: 'login/resetpassword.html',
}).result.finally(function() {
$state.go('home');
})
}
})
and close button markup
<div class="reset_section" ng-style="reset">
<span class="modal_close" ng-click="modalClose()">
<i class="material-icons">close</i>
this will open the modal on page loads, but the issue is, i can't able to close the modal by calling the function modalClose(), it is showing $uibModalInstance is not defined and also i need to open one more modal in the same page. after resetting the password, there is one button to login, after clicking the login button.it need to open login popup and have to close the reset password popup.How to do it, can anyone please help me

You could use $uibModalStack.dismissAll(); to dismiss all the existing modals.
In your case, You just need to add $uibModalInstance in the controller and try running it again. use $uibModalInstance.close() function.

Related

Angularjs Refresh page (f5) cancel routing

I have this routing on my webpage:
app.config(function($routeProvider)
{
$routeProvider
.when("/",
{
//
})
.when("/DokumentRoute",
{
templateUrl : "static/routes/dokument.html",
controller : "dokumentController"
})
.when("/MarkningarRoute",
{
templateUrl : "static/routes/markning.html",
controller: "markningarController"
})
.otherwise(
{
templateUrl: "static/routes/pageNotFound.html",
controller : "pageNotFoundController"
});
});
When I refresh the page (F5) I want to cancel the routing, meaning I don't want to show anything within the ng-view tag
<div ng-view id="view"></div>
This is what happens now:
When I start the web page it shows no routing-page. I click on "dokument" and it routes to the dokument page, which shows in the ng-view tag.
When I hit F5 the page refreshes, but it STILL SHOWS the dokument route!
This is what I want:
I want the routing to cleared. I want the web site to look like when I first entered it. (nothing showing in the ng-view tag)
How can I fix this?
If anyone is interested, this is how I solved it:
app.run(function ($location, $rootScope) {
$rootScope.$on('$routeChangeStart', function (event, next, current) {
if (!current) {
$location.path('/');
}
});
});

Share modal to the social network

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.

Closing all modals on AngularJS

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();
};
)

Angularjs - Clearing sticky state in angular ui-router

I am trying to add multiple tabs in my angularjs application.
On click of any menu item, I open the view in a new tab.
User have a optin to close any existing tab and he can click the menu option again to opne the view again as a tab.
Till now all this is working fine, but the issue is when the tab is closed I am not able to clear the previous sticky state. When user clicks on the same menu the new view is loading with the previous state.
On the close tab action I am trying to clear the state as following.
$stickyState.stateInactivated($state.$current)
$stickyState.reset('tabs.survey')
My routing for the tab is as following.
$stateProvider.state('tabs.survey', {
url: '/survey',
sticky: true,
views: {
'survey': {
templateUrl: 'partials/survey.html',
controller : 'surveyController'
}
}
});
I applied a workaround/hack to fix this issue
I added a new parameter to the route as following.
$stateProvider.state('tabs.survey', {
url: '/survey/:ts',
sticky: true,
views: {
'survey': {
templateUrl: 'partials/survey.html',
controller: 'surveyController'
}
}
});
Added the module run configruation like following.
app.run(function ($state, $rootScope, $stateParams) {
$rootScope.$state = $state;
$rootScope.$stateParams = $stateParams;
})
Finally on creating of a new tab item, I tried to changed the parameter to refresh the old state as following.
$state.go('tabs.survey', { "ts": 1 });
$state.go('tabs.survey', { "ts": 0 });
This is just a workaround. There can be some better solution for this, which I am not sure at this point of time.
All suggestions are welcome.

Angularjs deep linking to visual content (like modals)

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.

Categories