javascript - AngularJS - Ng-model becomes null after changing view -
so have page called personal info page assigned ng-models.
e.g.
<input type = "text" name = "foo_name" ng-model = "foo.name" /> <input type = "text" name = "foo_address" ng-model = "foo.address" /> <input type = "text" name = "foo_age" ng-model = "foo.age" /> then, there's continue button redirects new page called other details.
the continue button validating required fields if filled in. it's returning log if fields validated - either:
success
{result: { error: null } } fail
{result: { error: { blah blah blah } } } in other details page, it's grid of details entered on previous page. , then, there's "edit" button in page if wanted edit on personal info.
so i'm using ng-model retrieve data being stored in savedetailsinfo service.
$scope.retrievedata = function(datafromservice) { $scope.foo = { name: datafromservice.entry.name, address: datafromservice.entry.address, } } then, it's showing nicely , on respective fields. problem if i'm trying hit "continue" button again save changes. it's returning error these fields undefined, although values have been printed , populated on input fields.
to honest, have no idea why has become null since think did right in handling retrieving of data.
thanks in advanced help!
i can't recreate problem...but quick fix check if value null on continue function , if it's null read value ng-model again(as it's shown in dom tree) , using data initialize , continue need data.
many times happen because function initialized before dom gets data , hence null...
Comments
Post a Comment