AngularJS ng-controller directive
AngularJS instance
Add controllers 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 scope. </p></body></html>Running results:
Full Name: John DoeThis example demonstrates how to define a controller and scope usage.
Definition and usage
The ng-controller directive is used to add controllers to your application.
In the controller, you can write code, make functions and variables, and use scope objects to access.
grammar
<element ng-controller="expression"></element>
All HTML elements are supported.
Parameter value
| value | describe |
|---|---|
| Expression | Controller name. |
I hope to help students who study AngularJS and continue to supplement relevant knowledge in the future.