好的,以下是AngularJS Bootstrap学习笔记:

AngularJS Bootstrap学习笔记

什么是AngularJS Bootstrap?

AngularJS Bootstrap是一个基于Bootstrap样式库的AngularJS框架集成。它的目的是为了简化Bootstrap在AngularJS应用中的使用,同时提供一些额外的功能。

如何安装AngularJS Bootstrap?

你可以通过bower或者npm来安装AngularJS Bootstrap。

使用bower安装:

bashCopy Code
bower install angular-bootstrap

使用npm安装:

bashCopy Code
npm install angular-bootstrap

在你的HTML文件中引用AngularJS和AngularJS Bootstrap:

htmlCopy Code
<!DOCTYPE html> <html> <head> <title>My App</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/2.5.0/ui-bootstrap-tpls.min.js"></script> </head> <body ng-app="myApp"> </body> </html>

AngularJS Bootstrap指令

uib-alert

显示可关闭的警报框。

htmlCopy Code
<uib-alert dismiss-on-timeout="5000" type="success" close="closeAlert()"> <strong>Well done!</strong> You successfully read this important alert message. </uib-alert>

uib-accordion

创建可折叠的面板。

htmlCopy Code
<uib-accordion> <uib-accordion-group heading="First Heading"> Content of first panel. </uib-accordion-group> <uib-accordion-group heading="Second Heading"> Content of second panel. </uib-accordion-group> </uib-accordion>

uib-carousel

创建图片轮播。

htmlCopy Code
<uib-carousel interval="3000" no-wrap="false" active="active"> <uib-slide ng-repeat="slide in slides track by slide.id" index="slide.id" style="background-image: url({{slide.image}});"> <div class="carousel-caption"> <h4>{{slide.title}}</h4> <p>{{slide.text}}</p> </div> </uib-slide> </uib-carousel>

uib-datepicker

创建日期选择器。

htmlCopy Code
<uib-datepicker ng-model="myDate" min-date="minDate" max-date="'2019-06-22'" show-weeks="true"></uib-datepicker>

uib-modal

创建模态框(对话框)。

htmlCopy Code
<button class="btn btn-default" ng-click="open()">Open me!</button> <script type="text/ng-template" id="myModalContent.html"> <div class="modal-header"> <h3 class="modal-title">I'm a modal!</h3> </div> <div class="modal-body"> <p>Here's some content for the modal.</p> </div> <div class="modal-footer"> <button class="btn btn-primary" ng-click="ok()">OK</button> <button class="btn btn-warning" ng-click="cancel()">Cancel</button> </div> </script>
javascriptCopy Code
app.controller('ModalInstanceCtrl', function ($uibModalInstance) { var $ctrl = this; $ctrl.ok = function () { $uibModalInstance.close(); }; $ctrl.cancel = function () { $uibModalInstance.dismiss('cancel'); }; }); app.controller('MainCtrl', function ($uibModal, $log, $document) { var $ctrl = this; $ctrl.animationsEnabled = true; $ctrl.open = function (size, parentSelector) { var parentElem = parentSelector ? angular.element($document[0].querySelector('.modal-demo ' + parentSelector)) : undefined; var modalInstance = $uibModal.open({ animation: $ctrl.animationsEnabled, ariaLabelledBy: 'modal-title', ariaDescribedBy: 'modal-body', templateUrl: 'myModalContent.html', controller: 'ModalInstanceCtrl', controllerAs: '$ctrl', size: size, appendTo: parentElem, resolve: { items: function () { return $ctrl.items; } } }); modalInstance.result.then(function (selectedItem) { $ctrl.selected = selectedItem; }, function () { $log.info('Modal dismissed at: ' + new Date()); }); }; });

uib-pagination

创建分页。

htmlCopy Code
<uib-pagination total-items="totalItems" ng-model="currentPage" max-size="5" boundary-links="true"></uib-pagination>

总结

AngularJS Bootstrap是一个非常有用的工具,能够简化Bootstrap在AngularJS应用中的使用。本文介绍了一些最常用的AngularJS Bootstrap指令,并给出了相应的实例代码。