Home>

This article mainly introduces the angularjs ng-controller directive.Here is the collation of the ng-controller directive data.Attached code examples and renderings,Have

angularjs ng-controller directive

angularjs example

Add controller for application variables:

<! Doctype html>
<html>
<head>
<meta charset="utf-8">
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>
<div ng-app="myapp" ng-controller="myctrl">
full name:{{firstname + "" + lastname}}
</div>
<script>
var app=angular.module ("myapp", []);
app.controller ("myctrl", function ($scope) {
  $scope.firstname="john";
  $scope.lastname="doe";
});
</script>
<p>This example demonstrates how to define a controller and the use of scopes.</p>
</body>
</html>

operation result:

full name:john doe

This example demonstrates how to define a controller and the use of scopes.

Definition and usage

The ng-controller directive is used to add a controller to your application.

In the controller,You can write code,Make functions and variables,And use the scope object to access it.

grammar

<element ng-controller="expression"></element>

All html elements are supported.

Parameter value

value description
expression Controller name.

I hope to help students who are learning angularjs and continue to add relevant knowledge in the future.

  • Previous Summarize MD style related controls in Android
  • Next Thinkphp and Bootstrap combined to create a personalized pagination style (recommended)