AngularJs Tutorials
Important News
What is scope in angularjs?
Scope is a special javascript object which is userd for joining controller with the views. it join the controller and html view. Scope contains the model data. In controllers, model data is accessed via $scope object.
how to use scope in angularjs?
the $scope object pass as an argument in angular controller.
File name : index.php
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myanguapp" ng-controller="myCtrl">
<h1>{{websitename}}</h1>
</div>
<script>
var app = angular.module('myanguapp', []);
app.controller('myCtrl', function($scope) {
$scope.websitename = "itechtuto.com";
});
</script>
<p>The property "websitename" was made in the controller, and can be referred to in the view by using the {{ }} brackets.</p>
</body>
</html>
When adding properties to the $scope object in the controller, the view (HTML) gets access to these properties.
In the view, you do not use the prefix $scope, you just refer to a propertyname, like {{carname}}.
In the view, you do not use the prefix $scope, you just refer to a propertyname, like {{carname}}.
File name : index.php
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<input ng-model="name">
<h1>My name is {{name}}</h1>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.name = "Mahtab";
});
</script>
<p>When you change the name in the input field, the changes will affect the model, and it will also affect the name property in the controller.</p>
</body>
</html>
File name : index.php