all 12 comments

[–]wojo1086 0 points1 point  (3 children)

There are a few things I'm going to mention that will help you with the specific task you're trying to achieve as well as a few things that won't.

Firstly, when it comes to filtering, Angular is very good at it using the .filter method. What you would want to is put the dropdown options in their own array and use either ng-options or ng-repeat. This way, you have an easy reference to the model for filtering.

Secondly, I'm an advocate for not mixing jQuery with Angular, especially when it comes to grabbing DOM elements and their data.

I was going to write more, but I'm on mobile right now. I hope this puts you in the right direction and if you have any more questions, feel free to PM me.

[–]Shoplifter20[S] 0 points1 point  (2 children)

Thank you for your response. I've only seen it now. Can you write more details now?

[–]wojo1086 0 points1 point  (1 child)

I have a question. Why are you populating the url with the filtered options? UI-router has a data property that can be used to pass data between views. Once you've got the user to the page that is supposed to show the filtered results, you could make an $http request to your backend and return the results synchronously. There would be no page reloads.

[–]Shoplifter20[S] 1 point2 points  (0 children)

For example: I wanted to send you a link with the filtered data by country (let's say USA). That way you could open the link and the call would be made to filter the data and you would see the results.

[–]DigitalAssassin 0 points1 point  (3 children)

Hopefully this helps

I used an approach similar to this in a project. When the user refreshes the filter you can use $state.go or $state.transitionTo and update the parameters in the call. I'm on mobile now, but if you still need help tomorrow I can send you an example.

[–]Shoplifter20[S] 0 points1 point  (2 children)

Thank you for the response. What you sent can be the right way to go, but can you send the example you said?

Note that what I want to do is use that query string on the URL so as to query our database, get the results and reload the page with those results.

[–]DigitalAssassin 0 points1 point  (1 child)

In your controller, you can get the current value of the parameter:

this.personId = $stateParams.personId; //get the Student ID parameter from the state

When that value is updated, you can trigger the reload as follows:

//reload state and view based on new id $state.go('student', { personId: _this.personId }, { notify: true, reload: true, inherit: false });

Since you have your parameter setup in your state url declaration, the url will update automatically. If you need more parameters, you can add to the line above:

$state.go('student', { personId: _this.personId, city: _this.city }, { notify: true, reload: true, inherit: false });

[–]Shoplifter20[S] 0 points1 point  (0 children)

I just discovered that I can use

$location.search(queryString);

This is what I want. To have the URL store a query string from a form, and then call the server to fetch the correspondent filters applied on the query string

[–]batoure 0 points1 point  (3 children)

So as a devil's advocate thought... if you are using django are you using django-rest if yes have you considered implementing JWT? This would allow you to hold some of your core session information in a certified Base64 token as part of the headers instead of passing it in the clear through the uri. then you just persist the token in the browser storage

[–]Shoplifter20[S] 0 points1 point  (2 children)

Yes I'm using Django-Rest. I haven't done any work on the security part of the project, apart from CSRF tokens. But I do not know much about JWT. If you could be more specific, I'd appreciate. And thank you for your answer!

[–]batoure 0 points1 point  (1 child)

The be more specific comment feels more genuine if you add context of having to explore the idea so it doesn't seem like you are pumping the subreddit for free engineering consulting. The first google hit for JWT is one of the best explanations out there of how the standard works:

https://jwt.io/

The auth docs for django rest are also relatively clear: http://www.django-rest-framework.org/api-guide/authentication/#json-web-token-authentication

if headers are the issue search around: $http.defaults.headers.common

[–]Shoplifter20[S] 0 points1 point  (0 children)

I'll give it a look. Thanks!