How to call print function in new window after page is loaded? - angularjs

Ok i have this button :
and i have this function for confirm ticket:
$scope.ConfirmTicketPayOut = function (ticketPin, username)
{
$scope.ticketPin = ticketPin;
localStorage.setItem("ticketPin", ticketPin);
accountDataProviderService.confirmTicketPayOut(ticketPin, username)
.then(function (response) {
$scope.confirmTicketPayOut = response;
if ($scope.confirmTicketPayOut.Result == true)
{
var w = $window.open('/account/ticketprint');
angular.element(w).bind('load', function () {
w.print();
});
}
});
}
I have problem because when user click on button i need to open new window with data and to call print option. In this case i get print option and new window is open but the page is blank so my conclusion is that page is loaded after print option is appeared. I need to load page and show print option at same time, but without $timeout. Is that possible?

Try using angular event viewContentLoaded. call your method after this event is fired.
Example
$scope.$on('$viewContentLoaded', function() {
// Your method call
}

Related

Refresh page after APIQuickAction submission

I'm new in Lightning component development, and I'm trying to implement a lightning:datatable with several actions, like add a new line, delete a line, and create new line.
To create a line, I'm using a quick action, and I call it using quickActionAPI :
var actionAPI = component.find("quickActionAPI");
var args = { actionName :"Contrat_cadre__c.My_rule"};
var anAction = actionAPI.selectAction(args)
.then(function(result) {
})
.catch(function(e) {
if (e.errors) {
alert('The action is unavailable');
}
});
It's working as expected but well I need to manually refresh the page to see the new line in my datatable. But I don't know how to catch the subsmission of the quick action.
Try putting this in your "then" block: https://developer.salesforce.com/docs/component-library/bundle/force:refreshView/documentation
Thank you for your anwser, here is what I tried :
in controller.js :
var anAction = actionAPI.selectAction(args)
.then(function() {
console.log('enter in then');
helper.refreshPage();
})
in helper.js :
refreshPage: function (component)
{
console.log('helper method');
var action = component.get('c.**myApexController**');
action.setCallback(component,
function(response) {
var state = response.getState();
console.log(state);
if (state === 'SUCCESS'){
console.log('success');
$A.get('e.force:refreshView').fire();
} else {
//do something
}
}
);
$A.enqueueAction(action);
}
It seems that the then is fired when the action is invoked, so before the action submission. (the console.log display "enter in then" and "helper method" at this time, the other log does not display at all)

angularjs: $interval call never happen after it's cancelled

I've a requirement where as soon as i load a page it makes makes api call and
shows data on the page. and after every 15 sec it keeps loading the data an shows and i've a popup that has a click button function(ConfigModalButtonClick ). When i open the popup i wanted to stop the interval that makes the api call so for that i added $interval.cancel when popup is open but now when i click the button in popup the api call never happen. how can i make sure api call happens it looks like i need to call interval function again somewhere but not sure where??
the interval should run normally after 15 sec when i close the popup.
$scope.timeDelay = 15000;
$scope.loadData = function() {
$http.post(url,data
).then(
function(response) {
$scope.output = response.data;
},
function(response) {
$scope.retrieveErrorMssg = "Failed to retrieve required data. Try again.";
});
};
var interval = $interval(function() {
$scope.loadData();
}, $scope.timeDelay);
$scope.showConfigurationModal = function() {
$interval.cancel(interval);
$scope.state.settingModalVisible = true;
};
$scope.closeConfigurationModal = function() {
$scope.state.settingModalVisible = false;
// Need to explicitly trigger the dismiss function of the modal
$scope.settingModalDismiss();
};
$scope.ConfigModalButtonClick = function () {
$scope.state.settingModalVisible = false;
//some data manipulation
$scope.loadData();
};

Why does Angular JS count wrong clicks?

I have Angular JS code:
$scope.click = function (id) {
notificationsModal.confirm(function () {
$scope.$apply(function () {
console.log(id);
if(id == "test"){
$scope.contacts.blocked = $scope.contacts.blocked + 1;
}
});
}
}
When I do click I get confirm JS window with cancel button. I push this button for canceling event. I do this operation 4 ones.
After I confirm message and get 4 outputs console.log(id); in console. Why does it work for each click if I did cancel and condition had not been executed?

showing progressbar while function fetching data from database

I have a button on this button click I am calling a function e.g
<button ng-Click=”getData()”></button>
<div class=”Progressbar” ng-show=” showProgress “></div>
controller:
$scope.showProgress = false;
$scope.getData = function () {
$scope.showProgress = !$scope.showProgress;
myRepository.getAllData();
}
This function is taking longer time to fetch data from Database.
I want to show a SPINNER while data is getting fetched.
But this “Div” is shown only after whole function has been completed.
I want it to be shown before the completion of function.
How I can achieve that?
Set showProgress = true before loading data, and to false once data is loaded. For reliable behavior make myRepository.getAllData return promise, and then use its then method to hide spinner:
$scope.getData = function() {
$scope.showProgress = true;
myRepository.getAllData().then(function() {
$scope.showProgress = false;
});
}

still the navigate triggers and upate my url, the method is not calling

In my backbone app, i use the requirejs to load the js files. as well i need different views, there is no.of links are there in my drop down menu. according to the drop down menu i a adding the #url example:
http://localhost:85/bino/html/interface-I.html#projectName/project11
the navigate method works fine and updating the url, also whenever i copy and paste this url to any other browser / refresh with current hash state my router methods works fine.
But click on link in the drop down menu not working, the method not calling... what would be the reason and how can i fix this..?
my code: main js file (part of code)
var extender = _.extend({},backBone.Events);
var params ={
boardHolder :$('.boardHolder'),
column :3,
space :30,
extender :extender
};
var listApp = new routerer(params);
backBone.history.start();
extender.bind("list:selected",function(post){
listApp.navigate(post.category+'/'+post.filter);
});
my router code :
define(["backBone","singleton","listCollection","listView","listViews"],function(Backbone,singleton,listCollection,listView,listViews){
singleton.router = Backbone.Router.extend({
routes:{
"" :"appView",
"post" :"postView",
"projectName/:id" :"projectNameView",
"assignedTo/:id" :"assignedToView",
"sortBy/:id" :"sortByView"
},
initialize:function(params){
this.params = params;
this.collection = new listCollection;
console.log('i am called');
},
hashView:function(){
console.log('from hash view');
},
appView:function(){
var that = this;
// var defaultApp = new listCollection();
this.collection.fetch({
success:function(data){
new listViews({model:data,params:that.params})
}
})
},
projectNameView:function(thisView){ // not calling not sync
console.log('called',thisView); // on click not works
},
assignedToView:function(thisView){ // not calling not sync
console.log(thisView); // on click not works
},
sortByView:function(thisView){ // not calling not sync
console.log(thisView); // on click not works
}
});
return singleton.router;
})
thanks in advance.
navigate only updates the url, you also have to call the route function by setting the trigger option to true. If you'd like to update the URL without creating an entry in the browser's history, also set the replace option to true.
listApp.navigate(post.category+'/'+post.filter);
would become
listApp.navigate(post.category+'/'+post.filter, {trigger: true});

Resources