UI-Bootstrap示例不起作用

时间:2014-03-17 14:06:49

标签: javascript angularjs twitter-bootstrap angular-ui-bootstrap

我们正在尝试使用UI-Bootstrap http://angular-ui.github.io/bootstrap/

尝试通过示例工作,似乎没有任何工作。根据文档我们只需要引用angular和bootstrap css。但是,似乎我们还需要添加对ui-bootstrap-tpls-0.10.0.js的引用!?

请有人请详细说明以下为什么不起作用,这是代码直接在他们的网站上!: -

<!DOCTYPE html>
<html lang="en" ng-app="bootstrapDemoApp" id="top">
<head>

<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.8/angular.min.js"></script>
<script src="script/ui-bootstrap-tpls-0.10.0.js"></script>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet"/>

</head>
<body ng-app>

<div ng-controller="DatepickerDemoCtrl">


    <h4>Inline</h4>
<div style="display:inline-block; min-height:290px;">
  <div class="well well-sm" ng-model="dt">
      <datepicker min="minDate" show-weeks="showWeeks"></datepicker>
  </div>
</div>
</div>


<script>var DatepickerDemoCtrl = function ($scope) {
$scope.today = function() {
$scope.dt = new Date();
};
$scope.today();

  $scope.showWeeks = true;
  $scope.toggleWeeks = function () {
    $scope.showWeeks = ! $scope.showWeeks;
  };

  $scope.clear = function () {
    $scope.dt = null;
  };

  // Disable weekend selection
  $scope.disabled = function(date, mode) {
    return ( mode === 'day' && ( date.getDay() === 0 || date.getDay() === 6 ) );
  };

  $scope.toggleMin = function() {
    $scope.minDate = ( $scope.minDate ) ? null : new Date();
  };
  $scope.toggleMin();

  $scope.open = function($event) {
    $event.preventDefault();
    $event.stopPropagation();

    $scope.opened = true;
  };

  $scope.dateOptions = {
    'year-format': "'yy'",
    'starting-day': 1
  };

  $scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'shortDate'];
  $scope.format = $scope.formats[0];
};

</script>


</body>
</html>

2 个答案:

答案 0 :(得分:4)

UI Bootstrap是一个单独的角度模块,您必须将其注入模块:

将标记更改为:

<body ng-app="YourAppName">

并将其添加到脚本的开头:

angular.module('YourAppName', ['ui.bootstrap']);

您必须将控制器添加到您的应用中:

angular.module('app').controller(DatepickerDemoCtrl);

答案 1 :(得分:3)

你需要注入&u ;.bootstrap&#39;在你的应用程序中。

这是一个例子。

var app = angular.module('bootstrapDemoApp', ['ui.bootstrap']);

希望这有帮助。