📜  anjular js - Javascript (1)

📅  最后修改于: 2023-12-03 14:39:14.976000             🧑  作者: Mango

AngularJS - Javascript

AngularJS is a powerful and popular Javascript framework used for building dynamic web applications. It is a client-side MVW (Model-View-Whatever) framework that provides everything needed to build rich web applications.

Key Features

Some of the key features of AngularJS include:

  • Two-way data binding.
  • Dependency injection.
  • Directives for creating reusable components.
  • Filters for manipulating data.
  • Services for sharing data between components.
  • Routing for handling page navigation.
  • Testing support with Karma and Jasmine.
Getting Started

To get started with AngularJS, you can download it from the official website or use a CDN.

Example Code
<html ng-app="myApp">
<head>
    <title>AngularJS Example</title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>   
    <script>
        var app = angular.module('myApp', []);
        app.controller('myCtrl', function($scope) {
            $scope.firstName= "John";
            $scope.lastName= "Doe";
        });
    </script>
</head>
<body>

<div ng-controller="myCtrl">
    <p>First Name: {{firstName}}</p>
    <p>Last Name: {{lastName}}</p>
</div>

</body>
</html>
Directives

One of the most powerful features of AngularJS is directives. Directives allow developers to create reusable components that can be used throughout an application. AngularJS comes with several built-in directives, such as ng-model, ng-repeat, and ng-show, but developers can also create custom directives to fit their application's needs.

Example Custom Directive
app.directive("myDirective", function() {
    return {
        template : "<h1>Hello World</h1>"
    };
});
Conclusion

AngularJS is a powerful framework that provides everything needed to build dynamic web applications. With rich features such as two-way data binding, dependency injection, and directives, AngularJS can help developers create reusable and maintainable code.