Not Able To Fetch Scope Value In Back Button Method In Ionic
The scope is not the model.
I would suggest you to watch this video from Miško Hevery where he talks about the problem you're having. At some point he says something like this:
Whenever you have ng-model there’s gotta be a dot in there somewhere. If you don’t have a dot, you’re doing it wrong.
Anyway, if you want to fix your problem you should define a model in your controller.
The solution is to create one:
.controller('mystate2Ctrl', function($rootScope, $scope, $state) {
$scope.mymodel = { getamt: 0 };
});
Now you can reference your model in your views using the dot and your view should look something like this:
<ion-viewview-title="my-app"><ion-nav-buttonsside="right"class="button-clear"ng-click="myGoBack(mymodel.getamt)"><iclass="icon ion-ios7-arrow-back"></i> Not updating Amt {{mymodel.getamt}}
</ion-nav-buttons><ion-contentclass="has-subheader"padding-bottom="true"><divclass="row"><divclass="col col-30"><inputtype="text"placeholder="70"ng-model="mymodel.getamt"></div><divclass="col col-30 item">
Getting Amt here: {{mymodel.getamt}}
</div></div></ion-content></ion-view>
If you want to see how it works you can check my plunker.
Probably the best approach is the one John Papa suggests in his Angular guidelines.
If you read carefully the controllerAs View Syntaxhere he states why you should go for this approach:
Why?: It promotes the use of binding to a "dotted" object in the View (e.g. customer.name instead of name), which is more contextual, easier to read, and avoids any reference issues that may occur without "dotting".
Why?: Helps avoid using $parent calls in Views with nested controllers.
This is a second plunker with the controllerAs sample.
Solution 2:
It seems like because, your Getting Amt here: {{getamt}}
and Not updating Amt {{getamt}}
in two different directives. So make sure they both can access mystate2Ctrl
.
And try to define the variable in the controller itself.
.controller('mystate2Ctrl', function($scope, $stateParams, $localstorage, $rootScope, $ionicHistory) {
$scope.getamt = 0;
// your code
})
HTH
Post a Comment for "Not Able To Fetch Scope Value In Back Button Method In Ionic"