I have an angular.js application, where I am trying to redirect usgin the following code:
this.openPresentationDetails = function (presentationToShow) {
$location.path("/presentation");
};
It redirects to the proper page, however, the page appears greyed out. I have tried linking to other pages, and the result is the same.
Any ideas? Thanks.
I was invoking openPresentationDetails(...) from a modal form, I had to close the modal first and then redirect.
Related
My main issue is the following. I'm redirecting a page using the router in an AngularJS application to a Angular application. This works fine but when trying to go back to the page you came from you'll have to click the back button twice because when on a page going to a route, you load to route itself and then you redirect.
Example: you're on page A (AngularJS), you go to page B (AngularJS route) which redirects to C (Angular application).
When on page C you use the back button and as a user you expect to go back to page A but instead you go to page B and are redirected again to C.
Right now I think about detecting if the back button was clicked and the going back in the history with
window.history.go(-2)
Going back in the history works and I found a lot of questions and answers on SO to detect clicking the back button. But these ways of detecting the back button do not work when your origin is an AngularJS application and your code is in your Angular application.
Any idea how to detect the back button when your previous page was not the same application?
For now I came up with this solution.
In the routing of my AngularJS app I used:
redirectTo: function(routeParams) {
window.location = 'http://externalpathtoAngularApp';
}
and then in the Angular app in the controller of the page that is redirected to I added the following to the constructor of my class
if (document.referrer === 'http://originOfAngularJSApp') {
window.onpopstate = function () {
console.log(document.referrer);
};
history.pushState({}, '');
}
and also add this HostListener in the class after the constructor
#HostListener('window:popstate', ['$event'])
onPopState(event) {
if (document.referrer === 'http://originOfAngularJSApp') {
window.history.go(-2);
}
}
This is somewhat satisfying but it doesn't cover all the scenario's yet. For example if you come from app A and are redirected to C, then it goes back to A is expected.
But if you come from A redirected to C and then go to D, F... (in the Angular app) and then go back to C using the back button and finally using the back button to go to A you will be redirected to C again.
So in this case it's not completely covered yet.
I am trying to redirect to another url using state.go
$state.go("description-page", {disease: 'Thyroid'});
I am not even getting the scroll on the page. But when I refresh it, it works. Can anyone please help?
Thanks.
It resolved by putting timeout,
$timeout({
$state.go("description-page", {disease: 'Thyroid'});
},1000)
I have few links in a page. There are few links which will be visible if you scroll down the page..
I am using C# - Protractor for script automation.
It says that element is displayed, when i check boolean condition. But if i click the link it does not navigate to the actual page.
When use debug, while executing the click command if i scroll down the page then it works fine. How to resolve this scroll down issue?
IJavaScriptExecutor js = ngDriver as IJavaScriptExecutor;
js.ExecuteScript('arguments[0].click()', targetElement);
Getting error that Too many characters in character literal
Is this syntax correct?
Thanks
This worked for me
var elem = driver.FindElement(By.CssSelector("something"));
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].scrollIntoView(true);", elem);
I have a collapsible sidebar navigation, and any time users click a link on it, I have the sidebar hide automatically. I achieve this in the run method by using the following code:
app.run(function($rootScope) {
$rootScope.$on('$routeChangeSuccess', function () {
$rootScope.closeNavigation();
})
});
Where app is my Angularjs module.
The problem is that it gets a little unintuitive to use, when you click a link in the navigation for the page you're already on, and then nothing happens. What I would like is to have the sidebar close anyway, so that the users still get focus on the content, even if it's the same content.
But Angularjs doesn't execute the $routeChangeSucess event, if there is no route change happening. So what can I use instead?
You simply need to use ng-show = isPanelVisible and ng-click = closePanel() on the html sidepanel tag (e.g. a <div>).
Then, define $scope.closePanel() in the controller associated to the actual view. For instance
$scope.closePanel = function() {
$scope.isPanelVisible = false;
}
See an example here. Code is here. Note that it doesn't use ng-show, but the behaviour is the same.
I'm a beginner with AngularJs and i have some trouble understanding how to use $cookieStore :/
I have a lot of buttons. Everytime a button is clicked, a distinct function is called in the controller, and in this function, i'm trying to store a value in a cookie
example :
$cookieStore.put('cookie', '1');
And at the loading of the page, i added this line :
alert($cookieStore.get('cookie'));
When we load the page for the first time, it's normal to get an "undefined" popup. But the problem is, even after clicking multiple buttons, i always got an undefined popup after refresh.
Here's a working demo : http://plnkr.co/edit/6kuqaT7ISpo7uEwLHcZn?p=preview
Please help
Thanks
I checked your plunker cookie is setting properly :-)
Use STOP AND RUN button for refresh :P
I saw similar problem with refresh + $cookieStore some time ago, try using sessionStorage, if your target browser(s) allow that.
What Angular version do you use?