I'm getting started with Angular.JS.
I have a number of views that share the same controller. Each view is a step in collecting data that is stored in the controller:
$routeProvider.when('/', {
templateUrl: 'partials/text.html',
controller: 'itemSubmitter'
});
$routeProvider.when('/nextThing', {
templateUrl: 'partials/nextthing.html',
controller: 'itemSubmitter'
});
The itemSubmitter controller:
$scope.newitem = {
text: null
}
Here's the first view:
<textarea ng-model="newitem.text" placeholder="Enter some text"></textarea>
<p>Your text is:
{{ newitem.text }}</p>
This works, live updating the 'Your text is:' paragraph.
However when the next view is loaded, {{ newitem.text }}
is reset to its default value. How can I make values stored in a controller instance persist across views?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…