Bahan Sudut - Pengaturan Lingkungan

Bagaimana Cara Menggunakan Material Angular?

Ada dua cara untuk menggunakan Material Angular -

  • Local Installation - Anda dapat mendownload library Angular Material menggunakan npm, jspm, atau bower di komputer lokal Anda dan memasukkannya ke dalam kode HTML Anda.

  • CDN Based Version - Anda dapat menyertakan file angular-material.min.css dan angular-material js ke dalam kode HTML Anda langsung dari Content Delivery Network (CDN).

Instalasi Lokal

Sebelum kami menggunakan perintah npm berikut, kami memerlukan instalasi NodeJS di sistem kami. Untuk mendapatkan informasi tentang node JS, klik di sini dan buka antarmuka baris perintah NodeJS. Kami akan menggunakan perintah berikut untuk menginstal perpustakaan Bahan Angular.

npm install angular-material

Perintah di atas akan menghasilkan output berikut -

[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 akan mengunduh file di bawah node_modules > angular-materialmap. Sertakan file seperti yang dijelaskan dalam contoh berikut -

Contoh

Sekarang Anda dapat memasukkan file css dan js ke dalam file HTML Anda sebagai berikut -

<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>

Program di atas akan menghasilkan hasil sebagai berikut -

Versi Berbasis CDN

Anda bisa memasukkan angular-material.css dan angular-material.jsfile ke kode HTML Anda langsung dari Jaringan Pengiriman Konten (CDN). Google CDN menyediakan konten untuk versi terbaru.

Kami menggunakan perpustakaan versi Google CDN selama tutorial ini.

Contoh

Sekarang mari kita tulis ulang contoh di atas menggunakan angular-material.min.css dan angular-material.min.js dari 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>

Program di atas akan menghasilkan hasil sebagai berikut -