AngularJS Tutorial - Assign a Default Value to a Model








Controllers in Angular provide the business logic to handle view behavior.

We can use controller to handle a user click event and prepare the model for the view template.

A controller should not reference or manipulate the DOM directly.

Example

The following code shows how to assign a Default Value to a Model.


<!--from ww  w .  j  a v  a 2s  .  com-->
<!doctype html>
<html ng-app>
<head>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js"></script>
    <script>
function MyCtrl($scope) {
  $scope.value = "some value";
}    
    </script>
    <link rel="stylesheet" href="css/bootstrap.css">
  </head>
  <body ng-app>
    <div ng-controller="MyCtrl">
      <p>{{value}}</p>
    </div>
  </body>
</html>

The code above is rendered as follows: