Angularjs Examples

AJS Examples

AngularJS Controller Function

In AngularJS, if you want to do some manipulation in the view you must provide or add behavior in the scope object. AngularJS allow you to add behavior in the form of function or method in $scope object. You can than use these method in your view by calling the method from controller.


myApp.controller('myController', ['$scope', function($scope) {
  $scope.sqrt = function(value) { return value * value; };

AngularJS Controller Function Example

<html ng-app="yourApp">
<title>My first AngularJS Controllers Function code</title>
<script SRC="">
<script type="text/javascript">
//Creating Modules and Controller here
var app = angular.module('yourApp', []);
app.controller('myController', function($scope) {
  $scope.sqrt = function(value) { return value * value; };
<div ng-controller="myController">
  The Square of 20 equals to : {{ sqrt(20) }}