Matériau angulaire - Configuration de l'environnement

Comment utiliser un matériau angulaire?

Il existe deux façons d'utiliser le matériau angulaire -

  • Local Installation - Vous pouvez télécharger les bibliothèques de matériaux angulaires en utilisant npm, jspm ou bower sur votre machine locale et l'inclure dans votre code HTML.

  • CDN Based Version - Vous pouvez inclure les fichiers angular-material.min.css et angular-material js dans votre code HTML directement à partir du Content Delivery Network (CDN).

Installation locale

Avant d'utiliser la commande npm suivante, nous avons besoin de l'installation de NodeJS sur notre système. Pour obtenir des informations sur le nœud JS, cliquez ici et ouvrez l'interface de ligne de commande NodeJS. Nous utiliserons la commande suivante pour installer les bibliothèques de matériaux angulaires.

npm install angular-material

La commande ci-dessus générera la sortie suivante -

[email protected] node_modules\angular-animate

[email protected] node_modules\angular-aria

[email protected] node_modules\angular-messages

[email protected] node_modules\angular

[email protected] node_modules\angular-material

npm téléchargera les fichiers sous node_modules > angular-materialdossier. Incluez les fichiers comme expliqué dans l'exemple suivant -

Exemple

Vous pouvez maintenant inclure le fichier css et js dans votre fichier HTML comme suit -

<html lang = "en">
   <head>
      <link rel = "stylesheet"
         href = "https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.css">
      <script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
      <script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-animate.min.js"></script>
      <script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-aria.min.js"></script>
      <script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-messages.min.js"></script>
      <script src = "https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.js"></script>
      
      <script type = "text/javascript">    
         angular.module('firstApplication', ['ngMaterial']);
      </script>
   </head>
   
   <body ng-app = "firstApplication" ng-cloak>
      <md-toolbar class = "md-warn">
         <div class = "md-toolbar-tools">
            <h2 class = "md-flex">HTML 5</h2>
         </div>
      </md-toolbar>
      
      <md-content flex layout-padding>
         <p>HTML5 is the next major revision of the HTML standard superseding HTML
         4.01, XHTML 1.0, and XHTML 1.1. HTML5 is a standard for structuring and
         presenting content on the World Wide Web.</p>
         
         <p>HTML5 is a cooperation between the World Wide Web Consortium (W3C) and
         the Web Hypertext Application Technology Working Group (WHATWG).</p>
         
         <p>The new standard incorporates features like video playback and drag-and-drop
         that have been previously dependent on third-party browser plug-ins such as
         Adobe Flash, Microsoft Silverlight, and Google Gears.</p>
      </md-content>
   </body>
</html>

Le programme ci-dessus générera le résultat suivant -

Version basée sur CDN

Vous pouvez inclure le angular-material.css et angular-material.jsfichiers dans votre code HTML directement à partir du réseau de diffusion de contenu (CDN). Google CDN fournit du contenu pour la dernière version.

Nous utilisons la version Google CDN de la bibliothèque tout au long de ce didacticiel.

Exemple

Maintenant, réécrivons l'exemple ci-dessus en utilisant angular-material.min.css et angular-material.min.js de Google CDN.

<html lang = "en" >
   <head>
      <link rel = "stylesheet"
         href = "https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.css">
      <script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
      <script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-animate.min.js"></script>
      <script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-aria.min.js"></script>
      <script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-messages.min.js"></script>
      <script src = "https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.js"></script>

      <script type = "text/javascript">    
         angular.module('firstApplication', ['ngMaterial']);
      </script>
   </head>
   
   <body ng-app = "firstApplication" ng-cloak>
      <md-toolbar class = "md-warn">
         <div class = "md-toolbar-tools">
            <h2 class = "md-flex">HTML 5</h2>
         </div>
      </md-toolbar>
      
      <md-content flex layout-padding>
         <p>HTML5 is the next major revision of the HTML standard superseding HTML 4.01,
         XHTML 1.0, and XHTML 1.1. HTML5 is a standard for structuring and presenting 
         content on the World Wide Web.</p>

         <p>HTML5 is a cooperation between the World Wide Web Consortium (W3C) and the Web
         ypertext Application Technology Working Group (WHATWG).</p>
         
         <p>The new standard incorporates features like video playback and drag-and-drop
         that have been previously dependent on third-party browser plug-ins such as Adobe
         Flash, Microsoft Silverlight, and Google Gears.</p>
      </md-content>
   </body>
</html>

Le programme ci-dessus générera le résultat suivant -