Aditya
Aditya

Reputation: 431

How to change URL without refreshing the Whole Page?

I'm developing a site in angular and suppose I have navigated to iphone detail page and its current url is "localhost:8080/iphone/details" . Now I have to implement a new functionality of applying coupons.In this suppose user clicks on some hyperlink from external site, "localhost:8080/iphone/details?promotionalCode=12345"

User will land on that page(page will load after that modal will pop up) and a modal pop's up . And here details of promo code i will fetch from query parameter.

But my requirement is if i click cross (dismiss modal) ,and modal closes and state of url should be changed to localhost:8080/iphone/details .

What i have done till now .

I have used $location.search().promocode to fetch promocode if this is valid than modal will pop up and on dismiss modal i'm calling function in which i'm resetting state using $window.location.href , but this is making the whole page getting refreshed. Any suggestion on this ?

Upvotes: 1

Views: 250

Answers (2)

RamaKrishna
RamaKrishna

Reputation: 217

You can use $stateProvider for this just give the state

    Example:   .state('app.page', {
            url: 'iphone/details',
            title: 'Coupon Applied', })

Upvotes: 1

Rahul Desai
Rahul Desai

Reputation: 15501

You will need to use $location.search().

To get the query parameter ?promotionalCode=12345, you will need to do $location.search('promotionalCode',12345).

Please see: AngularJS Documentation for $location

Upvotes: 1

Related Questions