未知提供者:$modalProvider <- $modal 错误,AngularJS [英] Unknown provider: $modalProvider <- $modal error with AngularJS

查看:24
本文介绍了未知提供者:$modalProvider <- $modal 错误,AngularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试实现引导模式窗口时不断收到此错误.可能是什么原因造成的?我已经从 http://angular-ui.github.io/bootstrap/#/modal<复制/粘贴了所有内容/a> 在这里.

I keep receiving this error as I'm trying to implement bootstrap Modal window. What could be the cause of it? I've copy/pasted everything from http://angular-ui.github.io/bootstrap/#/modal here.

推荐答案

当您为控制器、服务等编写依赖项而您尚未创建或包含该依赖项时,会发生此类错误.

This kind of error occurs when you write in a dependency for a controller, service, etc, and you haven't created or included that dependency.

在这种情况下,$modal 不是已知服务.听起来您在引导 angular 时没有将 ui-bootstrap 作为依赖项传递.angular.module('myModule', ['ui.bootstrap']); 另外,为了安全起见,请确保您使用的是最新版本的 ui-bootstrap (0.6.0).

In this case, $modal isn't a known service. It sounds like you didn't pass in ui-bootstrap as a dependency when bootstrapping angular. angular.module('myModule', ['ui.bootstrap']); Also, be sure you are using the latest version of ui-bootstrap (0.6.0), just to be safe.

该错误是在 0.5.0 版本中抛出的,但更新到 0.6.0 确实使 $modal 服务可用.因此,请更新到 0.6.0 版并确保在注册模块时需要 ui.boostrap.

The error is thrown in version 0.5.0, but updating to 0.6.0 does make the $modal service available. So, update to version 0.6.0 and be sure to require ui.boostrap when registering your module.

回复您的评论:这就是您注入模块依赖项的方式.

Replying to your comment: This is how you inject a module dependency.

<!-- tell Angular what module we are bootstrapping -->
<html ng-app="myApp" ng-controller="myCtrl">

js:

// create the module, pass in modules it depends on
var app = angular.module('myApp', ['ui.bootstrap']);

// $modal service is now available via the ui.bootstrap module we passed in to our module
app.controller('myCtrl', function($scope, $uibModal) {

});

更新:

$modal 服务已重命名为 $uibModal.

使用 $uibModal 的示例

// create the module, pass in modules it depends on
var app = angular.module('myApp', ['ui.bootstrap']);

// $modal service is now available via the ui.bootstrap module we passed in to our module
app.controller('myCtrl', function($scope, $uibModal) {
    //code here
});

这篇关于未知提供者:$modalProvider &lt;- $modal 错误,AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆