0

I'm currently working on a ASP.net test SPA (using angular) to understand the concepts.

Essentially, I have my ng-view which loads the views all gravy. However, I've noticed that when a new view is loaded, the controller information is destroyed.

The partial page is as follows:

Dashboard:

<div ng-controller="DashboardController">
{{ DashboardData }}
</div>

However, if I was to reload this partial view, the controller data would be destroyed and its as though the controller gets re-created. eg. I set dashboarddata to "Waffles", reload the dashboard view, and DashboardData is now "".

Is this standard behaviour, and if so, what are the ways I can work around this? Is it bad practice, or is this fairly common?

Alex
  • 397
  • 2
  • 15
  • 1
    are u talking about ng-view or ui-view? in any case when controller is re-activated it loses scope values. You might want to check how to persist the data using services... – Vishwanath Mar 12 '15 at 13:41
  • We're using ng-view. Ideally, I'd rather not have to use services. I understand though, I'll see what I can do. Thanks. – Alex Mar 12 '15 at 13:52
  • Although services are not meant for this purpose. But, they can be and are used in this situation for persisting the data. Check this question http://stackoverflow.com/questions/13882077/angularjs-passing-scope-between-routes – Vishwanath Mar 12 '15 at 13:56

0 Answers0