I declare variable object globally, and assigning it on http call which will run when angular controller loads, Then I'm assigning this object values to angular scope variable and retrieving it in ng-models. On some button click when I change one of ng-model values then it reflects back to Javascript global variable. Why?
This is my view page
<input type="submit" ng-click="Edit()" value="Edit" />
<form name="myEditUserForm" novalidate>
<input type="text" ng-model="Info.Name" required ng-blur="Change()">
<input type="text" ng-model="Info.MobileNo" required ng-blur="Change()">
<input type="text" ng-model="Info.Email" required ng-blur="Change()">
<input type="text" ng-model="Info.Gender" required ng-blur="Change()">
<input type="submit" ng-click="Update()" value="Save Changes" />
</form>
This is my Angularjs code
app.controller('SomeController', function ($scope, $http) {
var someList = {};
$http({
method: 'GET',
url: '/Dashboard/GetData',
dataType: 'JSON',
headers: { 'content-type': 'application/json' }
}).then(function (response) {
someList = {
Name: response.data.Name,
MobileNo: response.data.MobileNo,
Email: response.data.Email,
Gender: response.data.Gender
};
});
$scope.Edit = function () {
$scope.Info = someList;
};
$scope.Change= function () {
console.log($scope.UpdateProfile.Email, tenantList.Email);
if ($scope.Info.Email != someList.Email) {
alert('changed');
}
};
I want to get same data from someList to which I assinged.