Ionic - Show spinner after button is pressed - ionic-framework

This spinner option from ionic is spinning all the time Like here
<ion-spinner icon="spiral"></ion-spinner>
How to make the spinner spin only after user presses the button, not before!?

You can try this also inside your controller
$scope.show = function() {
$ionicLoading.show({
template: '<p>Loading...</p><ion-spinner icon="android"></ion-spinner>'
});
};
$scope.hide = function(){
$ionicLoading.hide();
};
You can call $scope.show($ionicLoading); to start the spinners and you can make it end with this $ionicLoading.hide();
of course you have to inject $ionicLoading in your controller.
It worked for me hope it will help you

You can simply show and hide ion-spinner directive. In the codepen link you can change the button part and paste this:
<button type="submit" ng-click="click()" class="button button-block button-positive">
<ion-spinner ng-hide="showing" class="spinner-energized"></ion-spinner>
<span class="button-text">Click me!</span>
</button>
and add to MainCtrl
$scope.showing = true;
$scope.click = function(){
$scope.showing = false;
}
so when you press the button spinner will show. Of course you need some logic to stop it but this is just to show you how you can handle this. Hope it helps.

HTML
<button ng-Click="someFunction()"></button>
Controller
$scope.someFunction = function(){
$ionicLoading.show({
noBackdrop :false,
template: ' <ion-spinner icon="spiral"></ion-spinner>',
duration :20000//Optional
});
//Do Something
$ionicLoading.hide();//Hide it after Something is completed
}
It will show spinner as soon as you press button .
Regards

Related

What is the need of $scope.closeModal?

Here is my code..If I remove close modal function,there is no effect. If I click any where outside the modal, the modal closes. But I need this close modal function as I need to set a flag in it for further use. How can I proceed further?
$scope.$on('$ionicView.afterEnter', function() {
$scope.openModal();
}
$ionicModal.fromTemplateUrl("settings/settingsModal.html", {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.modal = modal;
});
$scope.openModal = function(){
$scope.modal.show();
}
$scope.closeModal = function(){
$scope.modal.hide();
};
}
There are a two ways of implementing modal in Ionic. One way is to add separate template and the other is to add it on top of the regular HTML file, inside script tags. First thing we need to do is to connect our modal to our controller using angular dependency injection. Then we need to create modal. We will pass in scope and add animation to our modal.
After that we are creating functions for opening, closing, destroying modal and the last two functions are place where we can write code that will be triggered if modal is hidden or removed. If you don't want to trigger any functionality when modal is removed or hidden you can delete the last two functions.
Controller's Code:
.controller('MyController', function($scope, $ionicModal) {
$ionicModal.fromTemplateUrl('my-modal.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.modal = modal;
});
$scope.openModal = function() {
$scope.modal.show();
};
$scope.closeModal = function() {
$scope.modal.hide();
};
//Cleanup the modal when we're done with it!
$scope.$on('$destroy', function() {
$scope.modal.remove();
});
// Execute action on hide modal
$scope.$on('modal.hidden', function() {
// Execute action
});
// Execute action on remove modal
$scope.$on('modal.removed', function() {
// Execute action
});
});
HTML Code :
<script id = "my-modal.html" type = "text/ng-template">
<ion-modal-view>
<ion-header-bar>
<h1 class = "title">Modal Title</h1>
</ion-header-bar>
<ion-content>
<button class = "button icon icon-left ion-ios-close-outline"
ng-click = "closeModal()">Close Modal</button>
</ion-content>
</ion-modal-view>
</script>
There are also other options for modal optimization. I already showed how to use scope and animation. The table below shows other options.
Modal options
The close modal function is meant for situations where you would like to close the modal manually. For example after a certain time it has been open or if something happens/the user does something for example presses a button.
There are ways of listening to when the modal is hidden/removed which will suit your situation and needs. For example:
// Execute action on hide modal
$scope.$on('modal.hidden', function() {
// Execute action
console.log('modal was hidden');
});
// Execute action on remove modal
$scope.$on('modal.removed', function() {
// Execute action
console.log('modal was removed');
});
With these you should be able to do what I understood you are wanting to do.
Straight from the documentation: http://ionicframework.com/docs/api/service/$ionicModal/

Ionic ion-refresher attr on-pulling can not work

I want the search form hide on init, scroll down to show. But when I used on-pulling on ion-refresher,it didn't work.
code:
<ion-refresher pulling-text="Pull to refresh..." on-refresh="doRefresh()" on-pulling="showSearch()"></ion-refresher>
Check this may help you...
<ion-refresher
pulling-text="Pull to refresh..."
on-refresh="loadTransactionList()"
refreshing-text="Refreshing!">
</ion-refresher>
The controller method is:
$scope.loadTransactionList = function(){
console.log("Refresh called");
$scope.$broadcast('scroll.refreshComplete');
}

Jquery Accordion choosing correct selector

I'm struggling with plugging in the correct selector into jquery. When I plug in ".accordionButton" the entire div is clickable and the functionality works great. However, I want to make only the "h3.toggle a" clickable, but plugging that selector in doesn't work. Is there something else in the jquery I need to change here? Any advice is greatly appreciated. Thanks!
The HTML:
<div class="accordionButton">
<div class="case-top">
<div class="case-left"></div>
<div class="case-right">
<h3 class="toggle">Our Strategy and Results</h3>
</div>
</div><!--end case-top-->
</div><!--end button-->
<div class="accordionContent">sliding content here</div>
The JQUERY:
$(document).ready(function() {
//ACCORDION BUTTON ACTION (ON CLICK DO THE FOLLOWING)
$('.accordionButton h3.toggle a').click(function() {
//REMOVE THE ON CLASS FROM ALL BUTTONS
$('.accordionButton h3.toggle a').removeClass('on');
//NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
$('.accordionContent').slideUp('normal');
//IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
if($(this).next().is(':hidden') == true) {
//ADD THE ON CLASS TO THE BUTTON
$(this).addClass('on');
//OPEN THE SLIDE
$(this).next().slideDown('normal');
}
});
/*** REMOVE IF MOUSEOVER IS NOT REQUIRED ***/
//ADDS THE .OVER CLASS FROM THE STYLESHEET ON MOUSEOVER
$('.accordionButton h3.toggle a').mouseover(function() {
$(this).addClass('over');
//ON MOUSEOUT REMOVE THE OVER CLASS
}).mouseout(function() {
$(this).removeClass('over');
});
$('.accordionContent').hide();
});
You are using
$(this)
but you change the selector, you need to change all $(this) selectors to
$('.accordionButton')
FIDDLE
Ok, here is where I'm at... the buttons are now working correctly, but on click all the instances of .accordionContent open, not just next one. ( FYI, I removed the mouseover from this code snipped)
Jquery
$(document).ready(function() {
//ACCORDION BUTTON ACTION (ON CLICK DO THE FOLLOWING)
$('.accordionButton h3.toggle a').click(function() {
//REMOVE THE ON CLASS FROM ALL BUTTONS
$('.accordionButton h3.toggle a').removeClass('on');
//NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
$('.accordionContent').slideUp('normal');
//IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
if($('.accordionButton').next().is(':hidden') == true) {
//ADD THE ON CLASS TO THE BUTTON (correct)
$(this).addClass('on');
//OPEN THE SLIDE
$('.accordionButton').next().slideDown('normal');
}
});
I'm guessing the lines:
$('.accordionButton').next().slideDown('normal');
and
if($('.accordionButton').next().is(':hidden') == true) {
are the lines which need editing. I need these two lines to open and close just the "next" .accordionContent instances not all of the instances together.

Toggle visibility with jQuery is immediately collapsing

I am a beginner in jQuery and JavaScript. I have the following problem: Every time I try to open an div area it is immediately collapsing. The HTML is:
<ul class="information"><li><a class="opener" href="#">opener</a> <div class="slide-block"> ...
The JavaScript:
jQuery(".information .opener").on("click", function(event){
var opener = jQuery(this);
// Show/hide the content by toggling active class
opener.parent().find(".slide-block").slideToggle("fast",function(){
opener.parent().toggleClass("active");
});
// Return false to subdue the click
return false;
});
In think it has to do with an upgrade of jQuery...
Thanks in advance
Julius

Get the button clicked ID in the same function in dojo?

I don't know if it is an easy question but i couldn't find the solution. I want to create 10 buttons in dojo like the button below.
<div style="right: 1px">
<button data-dojo-type="dijit.form.Button" id="SaveChangesDataGrid1" onclick="SaveChanges()">
Save</button>
</div>
but each button with different ID but the same function onClick. so what i want is when the button is clicked the id of the clicked button will be known in the function.
I am using dojo 1.8 any ideas?.
Change your onclick="SaveChanges()" to onclick="SaveChanges(event)" or get rid of it and use data-dojo-props:
<button
data-dojo-type="dijit.form.Button"
data-dojo-props="onClick:SaveChanges"
id="SaveChangesDataGrid2"
>
SaveChangesDataGrid2
</button>
Start your SaveChanges() this way to get id:
require([
"dijit/registry",
"dijit/form/Button",
], function(
registry
) {
window.SaveChanges = function(event) {
var button = registry.getEnclosingWidget(event.target);
console.log("onclick id:", button.id);
}
});
​
See it in action at jsFiddle: http://jsfiddle.net/phusick/WfdKF/