Fetch data from URL using Angularjs - angularjs

How to fetch the data from URL and use it. I Have 2 pages where I am redirecting the data from one page to other.
Here is the code for first page:
{{child.name}}
on product.html how do I fetch the URL and the catid data.
If I use $location.path(); it is giving me an error
$location not defined
How do I fetch the information from URL?

If on product.html you are not using angular or any routing mechanism you could always get the current url using the following:
var url = window.location.href;
From here on, you will have to parse the corresponding query string parameters (in your case catid) in order to obtain the desired value. The following thread could give you some example on how to achieve that.

Related

Get a single page's URL metric based on its base URL, ignoring the query string

The hit URL of a single page can be different like /post/15777, /post/15777?fbclid=xxx or /post/15777?rel=notification.
I want to get the URL /post/15777 metric (pageviews) but could not by using the API method getPageUrl in matomo api module because it would think of them as different URL.
GET /?
module=API&format=JSON&method=Actions.getPageUrl&pageUrl=/post/15777&idSite=1&period=range&date=2018-12-12,2019-12-12&token_auth=xxxxxxxxxxxxxxxxxx
Solved
Instead of method Actions.getPageUrl with pageUrl parameter, use the Actions.get method with segment parameter of pageUrl contains a specific url segment=pageUrl=#/post/15777
GET /?module=API&format=JSON&method=Actions.get&segment=pageUrl=#/post/15777&idSite=1&period=range&date=2018-12-12,2019-12-12&token_auth=xxxxx

Angular state navigation - add querystring to URL

My application when starts can automatically navigate to a specified state like this:
localhost://start.html#/case
When a user navigates to this state some parameters are prepared internally to get specific data for templates shown in case state. I need to be able to have an URL with querystring added to the URL in order for the user to copy and paste it into his email or somewhere else. Something like this:
localhost://start.html?project=1234#/case
I have spent a considerable time trying to make it work. I tried
$location.search('project', '1234');
But could not get an URL that would actually work.
Please help me with this task.
Thanks
Hi you can add the parameters at the end of the url
localhost://start.html#/case?project=1234
then you can get the parameters in angular using $location
var projectId = $location.search().project;
// or
var projectId = $location.search('project');
// clear url
$location.search('project', null);

Passing data from ASP.MVC controller to Angular controller Typescript

I have an app that will be started from external app possibly with a parameter (only one) coming with url. I have a following Action inside my MVC Home Controller:
public JsonResult LoadParam()
{
var query = Request.Url.Query.ToString();
string id = HttpUtility.ParseQueryString(query).Get(0);
return Json(id);
}
My problem is how do I call this from angular code? Normally I would use Get, but then I am passing "Home/LoadParam" url and it does not make any sense. I tried passing $location.url(), but then I won't hit LoadParam() action since my single page app stands on Home/Index URL. Not to mention that I couldn't make $location to get me any result (always getting an empty string).
So, to sum up - my question is how do I call this action from angualr code to retrieve the value of parameter when the app is open?
You need to use the $location service to get the query parameters on the client side rather than get it from the server side.
//Access via property
var id = location.search().id;
//Access as array
var id = location.search()[0];
https://docs.angularjs.org/api/ng/service/$location

How to prevent Angular from turning URL hash into a path

I have an angular app with a number of links. Clicking each link displays a particular set of data. I would like each link to set a hash in the URL, like http://foo.com/bar#item1, and I'd also like to show the page with the particular set of data displaying when that URL with the hash is accessed directly.
I was hoping to do it by reading / manipulating the $location.hash(), but as soon as I inject $location into my controller, the #item1 in the URL changes to #/item1. Is there a way to prevent Angular from doing this, and what's the best way of setting up what I described?
You could pass parameters in the routes /bar/item1, catch it with $routeParams and if exist make $location.hash().
"controller"
var anchor = $routeParams.anchorBottom;
if(anchor){
$location.hash(anchor);
$anchorScroll();
}
"link to section"
$location.path('/heart/bottom');
"route"
.when('/heart/:anchorBottom',{
You could see this running here.

JsonStore - Load single record with a restful url?

All,
I have a JsonStore backing a form panel in my extjs app. I want to have the jsonStore load a single record based on an id value, but haven't found a good way to do that yet, and still keep the url restful.
My first attempt was to add a param to the jsonstore load() method with the id in it. That only adds the id as a request param, not attached to the url:
http://my-app/users/?id=123
instead of what i want:
http://my-app/users/123
Can someone help me out with this?
You can manually construct the URL that the store uses to query for data (via the implicit HttpProxy it creates for the URL). So your loading function would look like:
function store_refresh() {
json_store.proxy.conn.url = 'http://my-app/users/' + user_id;
json_store.reload();
}

Resources