Tuesday, April 28, 2020

AngularJS Class 2

AngularJS Extends HTML

AngularJS extends HTML with ng-directives.
The ng-app directive defines an AngularJS application.
The ng-model directive binds the value of HTML controls (input, select, textarea) to application data.
The ng-bind directive binds application data to the HTML view.

There are many integrated development environments you can use for AngularJS development, some of the popular ones are mentioned below. In our example, we are using Webstorm as our IDE.
  1. Webstorm
  2. Sublime Text
  3. AngularJS Eclipse
  4. Visual Studio

AngularJS First Example

1.First  Create a Html page 

<html>  
<head>  
.  
.  
</head>  
<body>  
.  
.  
</body>  
</html>  

2. Second, you need to include the AngularJS JavaScript file in the HTML page so we can use AngularJS:

<html>  
<head>  

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js">
</script>
</head>  
<body>  
.  
.  
</body>  
</html>  


3. Third Create Controller 
<html lang="en">  
<head>  
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular.min.js"></script>  
</head>  
<body>
  
<script>  
angular.module("myapp", [])  
    .controller("HelloController", function($scope) {  
        $scope.helloTo = {};  
        $scope.helloTo.title = "World, AngularJS";  
    } );  
</script>  
</body>  

4. then Create View 

<html lang="en">  
<head>  
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.5/angular.min.js"></script>  
</head>  
<body ng-app="myapp">  
<div ng-controller="HelloController" >  
<h2>Hello {{helloTo.title}} !</h2>  
</div>  
  
<script>  
angular.module("myapp", [])  
    .controller("HelloController", function($scope) {  
        $scope.helloTo = {};  
        $scope.helloTo.title = "World, AngularJS";  
    } );  
</script>  
</body>  


Controller Part


<script>  
angular.module("myapp", [])  
    .controller("HelloController", function($scope) {  
        $scope.helloTo = {};  
        $scope.helloTo.title = "World, AngularJS";  
    });  
</script>  
</html>  


View Part

<div ng-controller="HelloController" >  
<h2>Hello {{helloTo.title}} !</h2>  
</div>


1 comment: