Header('Location') equivalent in AngularJS - angularjs

I need to refresh the current page with new get variables. I've read that you need to inject $route and use the reload method, but this only reloads the current url.
I would like to essentially do something akin to PHP:
header('Location:currenturl?get1=value1&get2=value2')
In AngularJS, NOT send an http.get request, but force the browser to load a new URL in the same window (in this case the modified get url). How can I do this in AngularJS? Does reload accept a parameter for a custom URL?
*I've just began to learn AngularJS and JS a few days ago, sorry if this is an obvious question, but I can't seem to find an answer that doesn't open a new tab

$window.location.href
https://docs.angularjs.org/guide/$location

Why no plain old window.location?

Related

AngularJS ui.router -- How to keep URL patterns manageable

If we are using "ui.router" of angular JS module, will that module take control of all the URL navigation in the entire page?
I am using the $stateProvider.state method to register the mappings of URLs and States but as I am using it, I am observing that the state provider is taking control of routing all URL patters. For example, if I am having a jquery tabs pane in the same page somewhere, it is not working. The reason being, the jquery tabs are based on the HREF of the Anchors and this ui-router is taking charge of mapping them as well, to some states.
Can someone please confirm if it really is supposed to work like this?
No, as per I know, it should work fine with HREF,for example
link
In your case, for tabs you are specifying #(hash) in href and thats why its going through ui-router, I would suggest you to use <uib-tab> instead of simple jQuery tabs and thing will work as you needed.
If you are using # in anchor tag then it will always try to match it with url and if not found then it will redirect to defualt one but you can actually intercept url change request in run function and use preventDefault function for specific request which will stop url change request

AngularJS hash causes redirect to fail

I have build an AngularJS application and want to use paymill.com to offer different payment methods. I am currently struggling with PayPal.
This api-call allows me to specify a redirect url where the customer gets redirected to after the payment:
https://developers.paymill.com/API/index#create-new-payment-checksum
I get a response with this URL as 'return_url':
http%3A%2F%2Ftest.test.com%2F%23%2Fteatimes%2Fbuy%2Fp82uHoLI6z%2F1
which seems to be the correct encoding for:
http://test.test.com/#/teatimes/buy/p82uHoLI6z/1
Sadly the redirect after the payment does not work and simply redirects me to:http://test.test.com/?paypal_parameters/#/.
So it seems like that everything after the hashtag gets ommited...Is there a way to fix this on my end? I would rather not use html5 mode.
EDIT: If i use the above url without the '#' i get correctly redirect, but angularjs is unable to resolve this of course.
Why don´t you wanna use the html5 mode? you wouldn´t have any issue with the hashtag.
What angular method do you use for redirecting to the URL.

How to set dynamic url in pluoplad-angular-directive?

I am trying to use plupload-angular-directive in my Angular SPA. The problem is, the upload URL is not a constant and is generated on the server side every time I need to upload something.
So, as mentioned in the docs I have used the pl-url directive to set the URL on the front-end like this:
<button pl-upload=""
pl-auto-upload="true"
pl-files-model="multiFiles"
pl-url="{{imgActionUrl}}"
pl-progress-model="percent">Upload Images</button>
where, the imgActionUrl is fetched by my Angular controller and assigned to the $scope.
Debugging the application clearly showed that the URL is being properly set but even then, when the upload actually happens, it makes a POST to /upload.php rather than to the address mentioned in the directive.
Why is this happening?
After a lot of digging around, I posted an issue on the github page of the project:
https://github.com/sahusoftcom/plupload-angular-directive/issues/43
But it seems nobody is maintaining this repository and the owner redirected me to another library, jQuery-File-Upload.

sails couldn't read GET parameter from request after angular hashtag

I tried to integrated sails.js as a route controller and api management, using angular.js as frontend, but I found the problem when using angular to modify URL
For an example /
Original URL : http://localhost
after modify by $location.search({'lang':destLanguage});
Modified URL : http://localhost#?lang=fr
Then I am using $window.location.reload(); to reload the page to send the GET parameter to the sails controller, but when I debug at the page controller, I found that sails couldn't read the parameter from request.
req.param('lang') == undefined
I am not sure how to solve this issue. I tried to solve these issue for a whole few days.
Thanks,
After the hash are not query params for the server. It would need to be before the hash, or remove the hash all together.
http://localhost?lang=fr
instead just create function to incorporate into your app
var updateLang = function(lang){
window.location = 'http://localhost?lang=' + lang
}
The rest of the answer depends on if your angular is setup to use html5Mode = true. If so, then you can use angular's $location.search() to retrieve your values. If not, then you will need to find a plain javascript to grab that value either on page load or when / where you need it.

Angular loading page without template

I have a SPA that uses angular routing. I would like to have a certain link that will open a specific page (not using a template) when clicked.
In other words I would to have some links that simply act as regular links and redirect the user to a new page. I don't want these links load inside of the template.
Surely this has to be possible right?
Many Thanks,
Kiran
If I understood your question right, you wanna replace the enitre current page with a redirect to a new external page?
If that so, you can definately do that using $location service just a s follows:
$window.location.href = 'http://www.google.com';
Just put that into an ng-click, then inject the $location service into your controller and you are good to go.
Further documentation on :
https://docs.angularjs.org/guide/$location
similar question on :
Redirect to new Page in AngularJS using $location

Resources