Scope acts as the binding mechanism between the HTML view and the JavaScript controller, holding accessible properties and methods available to both.
When creating a controller in AngularJS, you include the $scope object as an argument.
Properties defined in the controller can be accessed in the view.
<div ng-app=”myApp” ng-controller=”myCtrl”>
<h1>{{carname}}</h1> </div> <script> var app = angular.module(‘myApp’, []);
app.controller(‘myCtrl’, function($scope) { </script>
|