为什么模块'ui.bootstrap'不可用?

问题描述:

我正在尝试这个简单的教程来尝试UI Bootstrap: https://scotch.io/tutorials/how-to-correctly-use-bootstrapjs-and-angularjs-together
但我遇到了两个问题。为什么模块'ui.bootstrap'不可用?

SyntaxError: expected expression, got '<' at ui-bootstrap-1.3.3.js:5:0

这是第一个问题。我没有编辑的文件中任何东西,但它说的第一行<!DOCTYPE html>

而另外一个意外的标记是如下:

Error: [$injector:modulerr] Failed to instantiate module app due to: [$injector:modulerr] Failed to instantiate module ui.bootstrap due to: [$injector:nomod] Module 'ui.bootstrap' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

我看到你所有相关的问题,一些他们建议包括其他依赖项,而其他建议确保依赖项的顺序。试过一切,但没有喜悦。

以下是我的html和js代码。请看看
HTML

<html> 
<head> 
<style type="text/css"> 
      @import "css/bootstrap.css"; 
      @import "css/style.css"; 
     </style> 
     <script src="js/angular.js"></script> 
     <script src="js/angular-animate.js"></script> 
     <script src="js/angular-touch.js"></script> 
     <script src="js/ui-bootstrap-1.3.3.js"></script> 
     <script src="js/app.js"></script> 
</head> 
<body> 
<div class="container" ng-app="app" ng-controller="mainController"> 

    <div class="text-center"> 
    <p>Example of Angular and the normal Bootstrap JavaScript components</p> 
    <p class="text-success">This will work</p> 
    </div> 

    <h2>Buttons</h2> 
    <div class="btn-group" data-toggle="buttons"> 
    <label class="btn btn-primary" ng-model="bigData.breakfast" btn-checkbox> 
     Breakfast 
    </label> 
    <label class="btn btn-primary" ng-model="bigData.lunch" btn-checkbox> 
     Lunch 
    </label> 
    <label class="btn btn-primary" ng-model="bigData.dinner" btn-checkbox> 
     Dinner 
    </label> 
    </div> 

    <pre><code>{{ bigData | json }}</code></pre> 

    <h2>Collapse</h2> 

    <a href="#" class="btn btn-primary" ng-click="isCollapsed = !isCollapsed"> 
    Toggle Panel 
    </a> 

    <div class="panel panel-default"> 
    <div class="panel-heading"> 
     <h4 class="panel-title"> 
     <a href="#" ng-click="isCollapsed = !isCollapsed"> 
      Collapsible Group Item #1 
     </a> 
     </h4> 
    </div> 
    <div collapse="isCollapsed"> 
     <div class="panel-body">Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS. 
     </div> 
    </div> 
    </div> 

    <pre><code>{{ isCollapsed }}</code></pre> 

</div> 
</body> 
</html> 

JS

angular.module('app', ['ngAnimate', 'ngTouch', 'ui.bootstrap']) 

.controller('mainController', function($scope) { 

    // BUTTONS ====================== 

    // define some random object 
    $scope.bigData = {}; 

    $scope.bigData.breakfast = false; 
    $scope.bigData.lunch = false; 
    $scope.bigData.dinner = false; 

    // COLLAPSE ===================== 
    $scope.isCollapsed = false; 

}); 

不知道发生了什么错误。

编辑 版本细节方面如下
引导v3.3.6


角动画
角接触 所有人都具有版本AngularJS V1.5.3

+0

似乎是你需要安装UI,引导,包括在您的项目的第二个错误在UI引导 – devqon

+0

的错误。 –

+0

@neha soni安装?是不是只是下载js文件并通过脚本标签添加足够?有没有独立的安装类的东西? –

确保ui-bootstrap-1.3.3已正确加载到您的应用中。

请在下面找到工作plunker:

http://plnkr.co/edit/evG4XQ9ih9Cx0d1WF6YU?p=preview

+0

我发现了一个快速修复。似乎在我的系统上下载的文件无法正常工作。 但是,如果我指的是链接:''it works。因此,现在我刚刚更换了uibootstarp导入线,其余的导入都是这样的 –

+0

很高兴你的问题得到了解决,如果对你有帮助,请更正答案 – varit05

+0

但是你可以看看在教程网站上,如果我们检查/取消选中任何项目,同样会立即反映在json输出中,类似于collapse,输出将更改为true/false,但是,内容没有在这里崩溃,但在教程网站上它的工作完全正常。任何想法? –

你缺少ui-bootstrap-tpls.js文件。

将此文件添加到您的网页。

见例如working plunkr