AngularJS 教程
本章節(jié)介紹了如何在你的 AngularJS 中使用 Bootstrap。
Bootstrap 中包含了大量的 Web 組件,根據(jù)這些組件,可以快速的搭建一個漂亮、功能完備的網(wǎng)站。
AngularJS 的首選樣式表是 Twitter Bootstrap, Twitter Bootstrap 是目前最受歡迎的前端框架。
你可以在你的 AngularJS 應(yīng)用中加入 Twitter Bootstrap,你可以在你的 <head>元素中添加如下代碼:
如果站點在國內(nèi),建議使用百度靜態(tài)資源庫的Bootstrap,代碼如下:
以下是一個完整的 HTML 實例, 使用了 AngularJS 指令和 Bootstrap 類。
AngularJS 指令 | 描述 |
---|---|
<html ng-app | 為 <html> 元素定義一個應(yīng)用(未命名) |
<body ng-controller | 為 <body> 元素定義一個控制器 |
<tr ng-repeat | 循環(huán) users 對象數(shù)組,每個 user 對象放在 <tr> 元素中。 |
<button ng-click | 當(dāng)點擊 <button> 元素時調(diào)用函數(shù) editUser() |
<h3 ng-show | 如果 edit = true 顯示 <h3> 元素 |
<h3 ng-hide | 如果 edit = true 隱藏 <h3> 元素 |
<input ng-model | 為應(yīng)用程序綁定 <input> 元素 |
<button ng-disabled | 如果發(fā)生錯誤或者 incomplete = true 禁用 <button> 元素 |
元素 | Bootstrap 類 | 定義 |
---|---|---|
<div> | container | 內(nèi)容容器 |
<table> | table | 表格 |
<table> | table-striped | 帶條紋背景的表格 |
<button> | btn | 按鈕 |
<button> | btn-success | 成功按鈕 |
<span> | glyphicon | 字形圖標(biāo) |
<span> | glyphicon-pencil | 鉛筆圖標(biāo) |
<span> | glyphicon-user | 用戶圖標(biāo) |
<span> | glyphicon-save | 保存圖標(biāo) |
<form> | form-horizontal | 水平表格 |
<div> | form-group | 表單組 |
<label> | control-label | 控制器標(biāo)簽 |
<label> | col-sm-2 | 跨越 2 列 |
<div> | col-sm-10 | 跨越 10 列 |
Scope 屬性 | 用途 |
---|---|
$scope.fName | 模型變量 (用戶名) |
$scope.lName | 模型變量 (用戶姓) |
$scope.passw1 | 模型變量 (用戶密碼 1) |
$scope.passw2 | 模型變量 (用戶密碼 2) |
$scope.users | 模型變量 (用戶的數(shù)組) |
$scope.edit | 當(dāng)用戶點擊創(chuàng)建用戶時設(shè)置為true。 |
$scope.error | 如果 passw1 不等于 passw2 設(shè)置為 true |
$scope.incomplete | 如果有一個字段為空(length = 0)設(shè)置為 true |
$scope.editUser | 設(shè)置模型變量 |
$scope.watch | 監(jiān)控模型變量 |
$scope.test | 驗證模型變量的錯誤和完整性 |