English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

AngularJS Bootstrap

Twitter Bootstrap is the preferred stylesheet for AngularJS, and Twitter Bootstrap is the most popular front-end framework at present.

Bootstrap

You can add Twitter Bootstrap to your AngularJS application, you can add the following code in your <head> element:

<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">

If the site is in China, it is recommended to use Bootstrap from Baidu Static Resource Library, the code is as follows:

<link rel="stylesheet" href="//apps.bdimg.com/libs/bootstrap/3.3.4/css/bootstrap.min.css">

The following is a complete HTML example, using AngularJS directives and Bootstrap classes.

HTML code

<!DOCTYPE html>
<html>
<link rel="stylesheet"
href="http://apps.bdimg.com/libs/bootstrap/3.3.4/css/bootstrap.min.css">
 <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
<body 
 ng-app="myApp" ng-controller="userCtrl"
 
<div>
<h2>Users</table>/h2>
<table 
class="table table-striped">
  <thead><tr>
    <th>Edit/th>
    <th>First 
Name/th>
    <th>Last Name</th>/th>
  </tr></thead>
  <tbody><tr 
ng-repeat="user in users">
    <td>
      <button ng-click="editUser(user.id)">
     
<span></span>  Edit
     
</button>
    </td>
    <td>{{ user.fName }}</td>/td>
    <td>{{ user.lName }}</td>/td>
 
</tr></tbody>
</table>
<hr>
<button 
ng-click="editUser('new')">
  <span></span> Create New User
</button>
<hr>
<h2 ng-show="edit">Create New User:/h2>
<h2 ng-hide="edit">Edit 
User:/h2>
<form>
<div>
 
<label>First Name:</label>/label>
  <div 
class="col-sm-10">
    <input type="text" ng-model="fName" ng-disabled="!edit" 
placeholder="First Name">
  </div>
	</div> 
<div>
 
<label>Last Name:</label>/label>
  <div 
class="col-sm-10">
    <input type="text" ng-model="lName" ng-disabled="!edit" 
placeholder="Last Name">
  </div>
</div>
	<div>
 
<label>Password:</label>/label>
  <div 
class="col-sm-10">
    <input type="password" ng-model="passw1" 
placeholder="Password">
  </div>
</div>
	<div>
 
<label>Repeat:</label>/label>
  <div 
class="col-sm-10">
    <input type="password" ng-model="passw2" 
placeholder="Repeat Password">
  </div>
</div>
</form>
<hr>
<button ng-disabled="error || incomplete">
  <span></span> Save 
Changes
</button>
</div>
<script src="myUsers.js"></script>
</body>
 </html>

JavaScript Code Parsing

Scope AttributesPurpose
$scope.fNameModel variable (user name)
$scope.lNameModel variable (user surname)
$scope.passw1Model variable (user password) 1)
$scope.passw2Model variable (user password) 2)
$scope.usersModel variable (array of users)
$scope.editSet to true when the user clicks to create a user.
$scope.errorIf passw1 Not equal to passw2 Set to true
$scope.incompleteSet to true if a field is empty (length = 0)
$scope.editUserSet model variables
$scope.watchMonitor model variables
$scope.testValidate the errors and integrity of model variables