My input field is connected to the ng-model as shown below.
<div ng-app="myApp" ng-controller="GlobalCtrl">
<input type="text" ng-model="FirstName">
{{FirstName}}
</div>
In my controller, console.log $scope.FirstName
shows me the correct values I enter in the view.
However, when I try to place the $scope
data into a structure resembling JSON, it returns as undefined.
myApp.controller('GlobalCtrl', function($scope) {
$scope.loadedata = {"asd":$scope.FirstName};
console.log($scope.FirstName); //this works fine
console.log($scope.loadedata); //but this comes out as undefined.
});
Currently, $scope.loadedata)
is showing up as undefined. What could be causing this? Am I doing something incorrectly?