Define object and set its value in scope

Description

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

Example


<!--  www .j av 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>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Example »




Controller
Directives
Expression
Filter
Form
Inject
Scope
Server
Style
Template
Utilities