Reputation: 61
I am new to AngularJS.
I have 2 views, first one is for customer and other for city. The customer view has some basic fields to add information about customer, including button to add new city.
If I press the "add new city" button, then the view for adding new city is rendered. After this, when I go back on customer view, all previous entered information is lost.
How to keep this information?
Upvotes: 0
Views: 1387
Reputation: 306
When you visit a view, angular instantiates the controller again, so if you want the data to be persistence in the app, you should make use of a service, and store the data there. So when the controller is being instantiated, the controller would load the data from the service.
Upvotes: 1
Reputation: 3252
You could add something like this after the form with the customer information. Evertyhing is done in the same template and same controller, so no route switching.
Note that the city
model is updated immediately when you typ the field. If you do not want this, you could implement a saveCity
method on the scope which write the city model into another model and call it via ng-click="saveCity()
.
<div ng-hide="citySaved">
<input type="text" ng-model="city" />
<button type="button" ng-click="citySaved = true">Save city</button>
</div>
Upvotes: 0
Reputation: 11
The reason is you are pressing back button between pages which has a same parent controller. Add different controller for pages will solve your issue.
Upvotes: 1