0

I am not able to enter the data to the previous page using ng-model. I moved to the next page after filling some data in textbox, after come to same page I want my data to be entered same as I entered previously, I write the code but its not working please tell me what I am doing wrong and thanks in advance

js code:

$scope.notesPage = function() {
        $rootScope.data = {
            Name:               $scope.prospectName,
        };
        $location.path('/prospectNotes');
    };

    $scope.addProspect = function() {
        $rootScope.data.ProspectNotes = $scope.notes;
        $scope.ProspectNotes = "";
    };

    function fillFormData() {
        $scope.prospectName = $rootScope.data.Name;
    }

    $scope.addProspectForm = function() {
        $location.path('/create');
        fillFormData();

    }

first html page

<div class="container" id="form-container">
    <div class="form-group">
        <label for="prospectName"> Prospect Name:
            <img src="images/required.gif" alt="Required" class="required-star">
        </label>

        <input type="text" id="prospectName" name="prospectName" ng-model="prospectName" class="form-control" required>
    </div>

    <div class="form-group">

        <button type="submit" class="col-sm-2 btn btn-primary" ng-click="notesPage()" style="margin-left:10px;"> Next </button>
    </div>
</div>

second html page

<div class="container" id="form-container">

    <div class="form-group">
        <label for="notes"> Notes for Prospect {{data.Name}}</label>
        <textarea rows="20" id="notes" name="notes" ng-model="notes" class="form-control"></textarea>
    </div>

    <div class="form-group">
        <input type="button" id="cancel-button" value="Back" class="col-sm-2 btn btn-primary" ng-click="addProspectForm()">
        <button type="submit" class="col-sm-2 btn btn-primary" ng-click="addProspect()" style="margin-left:10px;"> Add </button>
    </div>
</div>
ghybs
  • 47,565
  • 6
  • 74
  • 99
avi
  • 212
  • 1
  • 5
  • 15

1 Answers1

0

Use a factory to store your data and then retrieve the same.

check this one:

Can I keep the model value when click browser back button with angularjs?

Community
  • 1
  • 1
Vasu
  • 129
  • 2
  • 9