AngularJS Tutorial - Define object and set its value in scope








The following code shows how to define object and set its value in scope.

Example


<!--from  w ww  .j  a v  a  2s  .c  o  m-->
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.js"></script>
<script type='text/javascript'>
function MainCtrl($scope) {
    $scope.customer = {
        name: 'TTT',
        id: 0
    };
    $scope.getDetails = function () {
        $scope.customer.name = 'Test';
    };
}
</script>
</head>
<body>
  <div ng-app="">
    <div ng-controller="MainCtrl">
         <p> <a href="#" ng-click="getDetails()">Refresh</a> </p>
        <p>
            <input type="text" ng-model="customer.name" />
        </p>
        <p><span ng-bind="customer.name"></span></p>
    </div>
</div>
</body>
</html>

The code above is rendered as follows: