Now I have a page for user to enter some data, which is not form. Such as:
<input type='text' ng-model='ExpReport.ReportName' /> <input type='text' ng-model='ExpReport.startdate' />
there is a exit button to let user go back to where they came from. The problem is if user don't change or modify any input.( assume they just accidently get here) when they hit the exit button, they can directlly go back, but if they made some change, if they want to go back, I need to show a popup to confirm that they want to leave without saving data. How can I catch it?
I try to use $watch, but seems like doesn't work for me:
angular.forEach($scope.ExpReport,function(value,key){
$scope.$watch('value',function(oldvalue,newvalue){
var currenturl = $location.path();
if(currenturl.indexOf('editreport')>-1){
$scope.$on('$locationChangeStart', function( event,next,current) {
event.preventDefault();
$scope.existconfirm = true;
if(next.indexOf('editreport')>-1) {
$scope.existconfirm = false;
}
});
}
})
})