使用Bower添加ui.bootstrap依赖项

42

我正在尝试将ui.bootstrap依赖项添加到我的Angular项目中(我使用的是yeoman和bower)。 我做了这个:

  1. yo angular
  2. bower install angular-ui
  3. 然后我在我的index.html文件中添加了:<script src="bower_components/angular-ui-bootstrap/ui-bootstrap-tpls.js"></script> 和 <link rel="stylesheet" href="bower_components/angular-ui-bootstrap/ui-bootstrap-csp.css">
  4. grunt serve

然后我将ui.bootstrap依赖项添加到我的app.js中:

angular.module('angularuiprojectApp', [
  'ngCookies',
  'ngResource',
  'ngSanitize',
  'ngRoute', 'ui.bootstrap'])

当我尝试在Chrome上访问我的index.html时,出现以下错误:

Uncaught Error: [$injector:modulerr] 无法实例化模块angularuiprojectApp,原因是:Error: [$injector:modulerr] 无法实例化模块ui.bootstrap ,原因是:Error: [$injector:nomod] 模块'ui.bootstrap'不可用!您可以......1)

我不知道哪里错了,如果有人能帮忙解决这个问题就太好了... 谢谢。


你确定已经将正确的文件添加到 index.html 中了吗?它是否被配置不当的 bower-install 替换了?在浏览器中是否出现任何 404 错误? - Mikke
3个回答

59
您正在从Bower安装错误的软件包。 正确的安装方式是按照此处描述的步骤执行 bower install angular-bootstraphttps://github.com/angular-ui/bootstrap#installation 编辑: 截至2015年2月,该库的Bower版本位于https://github.com/angular-ui/bootstrap-bower上。
不幸的是,它目前仅包含AngularUI Bootstrap 0.12.0,根据我所知,它与Angular> = 1.3不完全兼容。 看起来维护者打算让AngularUI Bootstrap> = 0.13.0与Angular 1.3兼容,但似乎该版本的库尚未进入Bower兼容的存储库中。
不再是问题,现在提供和支持AngularUI Bootstrap 0.13.0版本。

2
使用安装angular-bootstrap也不起作用,我必须手动更新bower.json以添加依赖项。之后,它就可以工作了。 - user1260928
6
下次安装时,您可以使用“-S”或“--save”选项来保存安装信息。 - McMeep
1
@user1260928 你具体是做了什么?我也遇到了同样的问题。 - Sebastialonso
1
@Sebastialonso 如果你还在寻找解决方案,请查看以下链接 https://www.versioneye.com/javascript/angular-ui:angular-ui-bootstrap-bower/0.11.0 - mr. Holiday

3
bower install angular-ui-bootstrap --save

这也适用。

如果您在使用由Bower安装的版本时遇到任何问题,请参考此答案。似乎有一些版本问题,ui-bootstrap引用了该答案。


3

请安装与您的项目使用的Angular版本相对应的Bower版本。

我首先安装了;

bower install angular-ui-bootstrap-bower#0.13.4

我随后在bower.json文件中添加了以下内容:

"angular-ui-bootstrap-bower": "0.13.4"

1
你可以执行 "bower install angular-ui-bootstrap-bower#0.13.4 --save" <-- 添加 "--save"。这将为你在 bower.json 中添加依赖项。 - mvermand

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接