AngularJS and W3.CSS

You can easily use w3.css style sheet together with AngularJS. This chapter demonstrates how.


W3.CSS

To include W3.CSS in your AngularJS application, add the following line to the head of your document:

<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">

If you want to study W3.CSS, visit our W3.CSS Tutorial.

Below is a complete HTML example, with all AngularJS directives and W3.CSS classes explained.


HTML Code

<!DOCTYPE html>
<html>
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body ng-app="myApp" ng-controller="userCtrl">

<div class="w3-container">

<h3>Users</h3>

<table class="w3-table w3-bordered w3-striped">
  
<tr>
    
<th>Edit</th>
    
<th>First Name</th>
    
<th>Last Name</th>
  
</tr>
  
<tr ng-repeat="user in users">
    
<td>
      
<button class="w3-btn w3-ripple" ng-click="editUser(user.id)">✎ Edit</button>
    
</td>
    
<td>{{ user.fName }}</td>
    
<td>{{ user.lName }}</td>
  
</tr>
</table>
<br>
<button class="w3-btn w3-green w3-ripple" ng-click="editUser('new')">✎ Create New User</button>

<form ng-hide="hideform">
  
<h3 ng-show="edit">Create New User:</h3>
  
<h3 ng-hide="edit">Edit User:</h3>
    
<label>First Name:</label>
    
<input class="w3-input w3-border" type="text" ng-model="fName" ng-disabled="!edit" placeholder="First Name">
  
<br>
    
<label>Last Name:</label>
    
<input class="w3-input w3-border" type="text" ng-model="lName" ng-disabled="!edit" placeholder="Last Name">
  
<br>
    
<label>Password:</label>
    
<input class="w3-input w3-border" type="password" ng-model="passw1" placeholder="Password">
  
<br>
    
<label>Repeat:</label>
    
<input class="w3-input w3-border" type="password" ng-model="passw2" placeholder="Repeat Password">
 
<br>
<button class="w3-btn w3-green w3-ripple" ng-disabled="error || incomplete">✔ Save Changes</button>
</form>

</div>

<script src= "myUsers.js"></script>

</body>
</html>

 



Directives (Used Above) Explained

AngularJS Directive

Description

<body ng-app

Defines an application for the <body> element

<body ng-controller

Defines a controller for the <body> element

<tr ng-repeat

Repeats the <tr> element for each user in users

<button ng-click

Invoke the function editUser() when the <button> element is clicked

<h3 ng-show

Show the <h3>s element if edit = true

<h3 ng-hide

Hide the form if hideform = true, and hide the <h3> element if edit = true

<input ng-model

Bind the <input> element to the application

<button ng-disabled

Disables the <button> element if error or incomplete = true


W3.CSS Classes Explained

Element

Class

Defines

<div>

w3-container

A content container

<table>

w3-table

A table

<table>

w3-bordered

A bordered table

<table>

<
AngularJS W3.CSS

Login
ADS CODE