We are developing mobile app using ng-Cordova. We need get data from server when page load.So we write getting code in loadFeeds.example
page1:-
.controller('HomeSecondCtrl', function($scope,$http,$location,$window,$stateParams,$ionicHistory,$ionicActionSheet,BlankService,BlankFactory) {
$scope.loadFeeds();
$scope.loadFeeds = function () {
alert("Start");//getting code
}
$scope.toggleImage = function (index) {
$location.path("/page2");
}
})
page2:-
.controller('SelectCategoryCtrl', function($scope,$location,$ionicHistory,$window,$http,$ionicActionSheet,BlankService) {
$scope.back = function (){
$location.path("/page1");
}
})
When app load we calld page1. So alert Will show alert("Start");. Then we have one button action toggleImage. Using this we redriect to page2 upto this ever thing fine.
our problem is
Second page have back button so using that we redirect to first page. But now Alert not showing. loadFeeds not working. Please guide us why loadFeeds is not working when are back to page1 from page2.
Use
$scope.$on('$ionicView.enter', function(){
$scope.loadFeeds();
});
$ionicView.enter : The view has fully entered and is now the active view.
This event will fire, whether it was the first load or a cached view.
Hope it helps.
Related
The id's #switchtopagetwo and #switchtoindex are assigned to buttons that do what you can infer from the id's names. What I want to do is on click of the button, I want to redirect to the new page via window.location = url; and then run a function that renders some data on the page via pagetwoData() or pageoneData(), depending on where I am at the moment.
$('#switchtopagetwo').on('click', function () {
window.location = 'pagetwo.html';
pagetwoData();
});
//pagetwo.html button
$('#switchtoindex').on('click', function () {
window.location = 'index.html';
pageoneData();
});
When I comment out window.location, the functions run and I can see the data on the screen, but there's no page redirect even on clicking the button. When I click on the buttons fast enough, I can see the function's data being rendered for a split second and then disappearing. When I console.log certain items, I can see the console.log's appearing in the console and then disappearing the same way.
Clearly there is an issue with window.location. Is there better code I can use for clicking the button, redirecting the page to load the page-2 data, then clicking the button again to go back to page-1 data?
When you redirect to a new page, the entire page context is abandoned and replaced by the new page. Nothing which happens on the source page after that redirect can be relied upon to still happen. But anything on the target page that's loading will happen.
Instead of trying to get Page1 to tell Page2 to do something when it loads, just have that something happen on Page2. For example:
// on index.html
pageoneData();
$('#switchtopagetwo').on('click', function () {
window.location = 'pagetwo.html';
});
// on pagetwo.html
pagetwoData();
$('#switchtoindex').on('click', function () {
window.location = 'index.html';
});
Basically, for any given page, whatever you want to happen on that page when it loads should be executed on that page when it loads.
I try to find Q&A related to my question. But I couldn't find. I have created a code where if user click double or multi click at single link then he will redirect to error page.
My Code is
<script>
var doubleClick = false;
function myWillPageRedirect() {
if(!doubleClick) {
doubleClick = true;
window.open("errorPage.html");
}
}
</script>
But this is not working. Why?
I want to create a secure page generally we can see in some bank or financial website.
I want to create 'if user click window back button then he will redirect to error page.' OR if if click refresh button then same action will perform and redirect to error page. ..
If this all code can make in Linux server backend code. It would be great.
Please help. I am not saying to some create code for me , I am asking for help to some correct my code above or bit extra help to make them secure.
Thank you .
HTML:
Double-click me
JS:
if(performance.navigation){ //Check if the page was refreshed
if( performance.navigation.type === performance.navigation.TYPE_RELOAD ){
myWillPageRedirect();
}
}
function myWillPageRedirect() {
window.open("errorPage.html");
}
window.onhashchange = function() { //Check if the url has changed (in case of pressing back button)
myWillPageRedirect();
}
More infos about Performance.navigation
I’m trying to create a simple test where I click on a button in my Angular app. However, when I navigate to my Angular app it first redirects me to a non Angular login page.
So a user’s experience is as follows: The user navigates to https://test.com and then is redirected to a login page where they enter a username and password and click the Submit button. Then the app page loads which contains a button which they can click.
I’ve got my code working to the point where when I run protractor, I see a chrome window open, I see the login page appear and I can see text filling into both the ‘Username’ and ‘Password’ fields. However, right after that the chrome browser closes. I do not see my app page loads which contains the button I want to click.
The code I’m using to try and login is as follows (NOTE: username and password text were changed to something fake so I could post my question)
describe('Go to Test site', function() {
it('and login', function() {
browser.get('https://test.com');
browser.ignoreSynchronization=true;
element(by.name('login')).sendKeys('username');
element(by.id('cred_password_inputtext')).sendKeys('password');
element(by.id('cred_sign_in_button')).click();
//browser.ignoreSynchronization=false;
});
});
What is the next step? Should I be using “browser.ignoreSynchronization=false;”? Do I need to find the button element on the next page?
At this point I would be happy just to see my app page load so I can even see the button in the test browser. It closes so fast. This is my first question so I apologize if it's confusing. Thank you.
As mentioned by #Batajus you don't have any code, so the test execution has finished.
If you only need to logon once you can place the code in a beforeAll() and even make a method for it that holds all the logon logic, something like this
function logon(username, password) {
var EC = protractor.ExpectedConditions;
browser.get('https://test.contracts365.com');
browser.ignoreSynchronization = true;
// Wait for the url to be changed to the logon page
browser.wait(EC.urlContains('login.microsoftonline.com'), 5000);
// Do the logon magic
element(by.name('login')).sendKeys(username);
element(by.id('cred_password_inputtext')).sendKeys(password);
element(by.id('cred_sign_in_button')).click();
browser.ignoreSynchronization = false;
// Wait till you are back on the page
browser.wait(EC.urlContains('test.contracts365.com'), 5000);
}
describe('Go to Test site', function() {
beforeAll(function() {
logon('john#doe.com', 'Welcome123')
});
it('should do some tests', function() {
// do some tests
});
});
And then add your tests
Hope it helps
your browser closes, because the test execution has finished. So your next step is to find a button or another element on your next loaded page.
I recommend to use browser.wait(...) methods with Expected Conditions to wait until your next page is fully loaded and your elements become interactable.
I hope this solves your problems, otherwise please tell me so i provide another solution ;-)
I have a Backbone app with Rails on the back-end. Suppose you are on page http://localhost:3000/#home and then go to http://localhost:3000/#collection. When the user clicks the Back button, I want this to behave exactly like clicking a link to http://localhost:3000/#home or typing this URL in the address bar and pressing Enter.
However, what happens instead with the Back button is the code in the <script> tag in index.html is executed again:
<script>
$(document).ready(function () {
AudioFileApp.initialize();
});
</script>
As a result, my views are not created properly (like they are if you just enter the URL and press enter). I suspect the issue is related to this turbolinks/Backbone/Rails issue, as it fixed a problem I had with a history already started error: https://github.com/codebrew/backbone-rails/issues/134. However, I'm still having problems with the re-initialization, and as a beginner I'm totally stumped.
Is there a way to make sure Back will behave just like accessing the prior page via a link or the address bar?
Here is the actual initialization method if that helps:
initialize: function() {
var router = new AudioFileApp.Routers.Router({
$rootEl: $('#main'),
currentUser: new AudioFileApp.Models.User({ id: CURRENT_USER_ID })
});
var navbar = new AudioFileApp.Views.NavbarView();
$('#navbar').html(navbar.render().$el);
var audioPlayer = new AudioFileApp.Views.AudioPlayer();
$('#audio-player').html(audioPlayer.render().$el);
if (!Backbone.history.started) {
Backbone.history.start();
}
// Listen for Back button click
$(document).on('page:load', function () {
Backbone.history.stop();
Backbone.history.start();
});
}
The problem was that I didn't completely remove turbolinks.
http://blog.steveklabnik.com/posts/2013-06-25-removing-turbolinks-from-rails-4
I have a problem. I have a registry form and many other forms.
Now I want to check whether the form is dirty and then I bring a confirm box if they really want to leave/close this page.
First of all, when I go back with the browser's back button and not with my other button ([button..] just 4 example) the confirmation box shows up two times and after two times confirming I'm still on the same page, just the form is resetted. When I press my own everything works fine.
Secondly, when I close the browser, my confirmation box shows up and afterwards the browsers confirmation box also shows up, but I only want one of them.
$scope.$on('$locationChangeStart', function (event, next, current) {
if ($scope.requestForm.$dirty) {
if (!$window.confirm('Unsaved Changes, leave Page?')) {
//cancel leaving view2
//works when clicking links, but doesn't work when using the back button
event.preventDefault();
}
} else {
}
});
$scope.$watch("requestForm.$dirty", function (newval) {
window.myGlobalDirtyFlag = newval;
});
window.onbeforeunload = function (e) {
if (window.myGlobalDirtyFlag === true) {
if (!$window.confirm('Unsaved Changes, close Page?')) {
//cancel leaving view2
//works when clicking links, but doesn't work when using the back button
return false;
} else {
}
}
};
$scope.$on("$destroy", function () {
window.myGlobalDirtyFlag = false;
});
May someone also have an idea how I bring this into an AngularJS directive, so I don't have to copy this code for every site where I have a form on it. (Every page only has 1 form, but every form name is different!)
My controllers are in seperate javascript files, (function blablaController() {}) and I pass this per routeProvider in my config file (templateUrl: blabla.html, controller: blabalController)
Regards,
Anthrax
Here is a service and directive that answers your question. Probably the only change you might consider making to it is using $window instead of window inside the service. As the instructions state, you'll just add the attribute unsaved-changes-warning to your form.
https://github.com/facultymatt/angular-unsavedChanges