Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
دوره آموزش AngularJS - کنترل‌گرها (Controllers): http://blog.allii.ir/2016/01/angularjs-beginner-intermediate-course-controllers
<!DOCTYPE html>
<html lang="en">
<head>
<!-- AngularJS 1.4.8 !-->
<script src="../src/angular.min.js"></script>
<script src="module.js"></script>
<script src="addition-controller-params.js"></script>
</head>
<body ng-app="app">
<p ng-controller="AdditionController">
{{add(number, 2)}} is not the same as {{add(number, "2")}}
<br>
2 + 2 + 2 + 2 = {{add(2, add(2, add(2, 2)))}}
</p>
</body>
</html>
function AdditionController($scope)
{
$scope.number = 2;
$scope.add = function (operand1, operand2)
{
return operand1 + operand2;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<!-- AngularJS 1.4.8 !-->
<script src="../src/angular.min.js"></script>
<script src="module.js"></script>
<script src="addition-controller.js"></script>
</head>
<body ng-app="app">
<p ng-controller="AdditionController">
<select ng-model="operand1" ng-options="x for x in options"></select>
+ <select ng-model="operand2" ng-options="x for x in options"></select>
= {{add()}}
</p>
</body>
</html>
function AdditionController($scope)
{
$scope.operand1 = 0;
$scope.operand2 = 0;
$scope.add = function ()
{
return $scope.operand1 + $scope.operand2;
}
$scope.options = [0, 1, 2, 3, 4];
}
<!DOCTYPE html>
<html lang="en">
<head>
<!-- AngularJS 1.4.8 !-->
<script src="../src/angular.min.js"></script>
<script src="module.js"></script>
<script src="count-controller.js"></script>
</head>
<body ng-app="app">
<p ng-controller="CountController">
There are {{count()}} months in a year.
</p>
</body>
</html>
function CountController($scope)
{
$scope.count = function ()
{
return 12;
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<!-- AngularJS 1.4.8 !-->
<script src="../src/angular.min.js"></script>
<script src="module.js"></script>
<script src="empty-controller.js"></script>
</head>
<body ng-app="app">
<p ng-controller="EmptyController">
</p>
</body>
</html>
function EmptyController()
{
};
<!DOCTYPE html>
<html lang="en">
<head>
<!-- AngularJS 1.4.8 !-->
<script src="../src/angular.min.js"></script>
<script src="module.js"></script>
<script src="form-submit-controller.js"></script>
</head>
<body ng-app="app">
<div id="form_wrapper" ng-controller="FormSubmitController">
<form ng-show="notSubmitted">
<input type="text" name="feedback"/>
<input type="submit" value="Submit Feedback" ng-click="toggle()"/>
</form>
<div ng-hide="notSubmitted">Thanks for submitting your feedback!</div>
</div>
</body>
</html>
function FormSubmitController($scope)
{
$scope.notSubmitted = true;
$scope.toggle = function ()
{
$scope.notSubmitted = !$scope.notSubmitted
};
}
<!DOCTYPE html>
<html lang="en">
<head>
<!-- AngularJS 1.4.8 !-->
<script src="../src/angular.min.js"></script>
</head>
<body ng-app="app">
<!-- Other examples to be inserted here. -->
</body>
</html>
function MessageController()
{
this.message = "This is a model.";
}
<!DOCTYPE html>
<html lang="en">
<head>
<!-- AngularJS 1.4.8 !-->
<script src="../src/angular.min.js"></script>
<script src="module.js"></script>
<script src="message-controller-scope.js"></script>
</head>
<body ng-app="app">
<p ng-controller="MessageController">
{{message}}
</p>
</body>
</html>
function MessageController($scope)
{
$scope.message = "This is a model.";
}
<!DOCTYPE html>
<html lang="en">
<head>
<!-- AngularJS 1.4.8 !-->
<script src="../src/angular.min.js"></script>
<script src="module.js"></script>
<script src="message-controller-as.js"></script>
</head>
<body ng-app="app">
<p ng-controller="MessageController as controller">
{{controller.message}}
</p>
</body>
</html>
angular.module('app', []);
angular.module('app').config(['$controllerProvider', function ($controllerProvider)
{
$controllerProvider.allowGlobals();
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.