Assign a Default Value to a Model

Description

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.


<!-- w  ww .  ja  v  a  2 s  .  co m-->
<!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>

Click to view the demo





















Home »
  AngularJS »
    AngularJS Example »




Controller
Directives
Expression
Filter
Form
Inject
Scope
Server
Style
Template
Utilities