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

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.


<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)