Damodar Dahal
Damodar Dahal

Reputation: 569

angular-js: Multiple instances of controller being created in ui-router

I have noticed that, whenever a $state.go() is applied to a state with parameter(s) in AngularJS UI-Router, a new instance of the HTML content [for that view] is created each time. Not only the HTML content, but also the controller are being created as many times as newer params are appearing on the $stateParams after calling $state.go() in the program later on.

How do I stop new instances of HTML content and controller to stop appearing, while still passing the params to the $stateParams? I want to use the same controller, same scope and same HTML content for any data that $stateParams holds. Thank you very much in advance!

Upvotes: 1

Views: 1368

Answers (1)

Damodar Dahal
Damodar Dahal

Reputation: 569

YES, it is possible. Disable caching.

This is done in various ways. One of the ways would be to be disable caching while defining the states. Eg:

$stateProvider.state("home",
    {
        url:'/home',
        cache:false,
    }

Adapted from ui.router not reloading controller

Upvotes: 1

Related Questions