📅  最后修改于: 2023-12-03 15:13:24.111000             🧑  作者: Mango
AngularJS CDN (Content Delivery Network) is a way to quickly and easily access the AngularJS framework without having to download it manually. CDN servers host AngularJS files and make them available for use in web applications.
To use AngularJS CDN in your web application, follow these steps:
First, you need to add the AngularJS script tag to your HTML file. You can do this by adding the following code to the head of your HTML file:
<head>
...
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.0/angular.min.js"></script>
...
</head>
This will load the AngularJS script from Google's CDN server.
Once you have added the AngularJS script tag, you need to add it as a dependency in your application module. This can be done using the following code:
var app = angular.module('myApp', ['ng']);
This code adds the 'ng' module, which is the core AngularJS module, as a dependency to your 'myApp' module.
Once you have added the AngularJS module to your application, you can start using it to build your web application. Here are a few examples of how you can use AngularJS:
<div ng-app="myApp" ng-controller="myCtrl">
<input type="number" ng-model="num1">
<input type="number" ng-model="num2">
<p>Total: {{ num1 + num2 }}</p>
</div>
<script>
var app = angular.module('myApp', ['ng']);
app.controller('myCtrl', function($scope) {});
</script>
This code creates a simple form that adds two numbers together using AngularJS.
<div ng-app="myApp" ng-controller="myCtrl">
<ul>
<li ng-repeat="user in users">{{ user.name }}</li>
</ul>
</div>
<script>
var app = angular.module('myApp', ['ng']);
app.controller('myCtrl', function($scope, $http) {
$http.get("https://jsonplaceholder.typicode.com/users")
.then(function(response) {
$scope.users = response.data;
});
});
</script>
This code retrieves data from an API and displays it in a list using AngularJS.
AngularJS CDN is a powerful tool that simplifies the process of using AngularJS in web applications. By using a CDN, you can save time and simplify your coding, while also enjoying the benefits of faster loading times and always up-to-date files.