Xee*_*een 96 javascript modal-dialog angularjs
我一直在收到这个错误,因为我正在尝试实现bootstrap Modal窗口.可能是什么原因造成的?我在http://angular-ui.github.io/bootstrap/#/modal复制/粘贴了所有内容.
m59*_*m59 195
当您在控制器,服务等的依赖项中写入并且尚未创建或包含该依赖项时,会发生此类错误.
在这种情况下,$modal不是已知的服务.听起来你在引导角度时没有传递ui-bootstrap作为依赖.angular.module('myModule', ['ui.bootstrap']);此外,请确保您使用的是最新版本的ui-bootstrap(0.6.0),以确保安全.
版本0.5.0中引发了错误,但更新到0.6.0确实使$ modal服务可用.因此,更新到0.6.0版本并确保在注册模块时需要ui.boostrap.
回复您的评论:这是您注入模块依赖项的方式.
<!-- tell Angular what module we are bootstrapping -->
<html ng-app="myApp" ng-controller="myCtrl">
Run Code Online (Sandbox Code Playgroud)
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) {
});
Run Code Online (Sandbox Code Playgroud)
该$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
});
Run Code Online (Sandbox Code Playgroud)
Bre*_*ent 54
5年后 (这不会是当时的问题):
命名空间已更改 - 升级到较新版本的bootstrap-ui后,您可能会偶然发现此消息; 你需要参考$uibModal&$uibModalInstance.
CRE*_*OFF 22
对于今天我也遇到过的问题,这是一个额外的注意事项:当我打开我的源代码的minification/uglify时,我遇到了类似的错误"Unknown provider:$ aProvider".
正如Angular文档教程(段落:"关于缩小的注释")中所提到的,您必须使用数组语法来确保正确保留引用以进行依赖注入:
var PhoneListCtrl = ['$scope', '$http', function($scope, $http) { /* constructor body */ }];
Run Code Online (Sandbox Code Playgroud)
对于Angular UI Bootstrap示例,您提到您应该替换此:
var ModalInstanceCtrl = function ($scope, $modalInstance, items) {
/* ...example code.. */
}
Run Code Online (Sandbox Code Playgroud)
使用此数组表示法:
var ModalInstanceCtrl = ['$scope', '$modalInstance', 'items', function ($scope, $modalInstance, items) {
/* copy rest of example code here */
}];
Run Code Online (Sandbox Code Playgroud)
通过该更改,我的缩小的Angular UI模式窗口代码再次起作用.
ozk*_*ary 11
提供程序错误的明显答案是在添加ui-bootstrap的情况下声明模块时缺少依赖性.我们许多人没有考虑的一件事是升级到新版本时的重大变化.是的,以下应该可以工作,而不是引发提供程序错误:
var app = angular.module('app', ['ui.router', 'ngRoute', 'ui.bootstrap']);
app.factory("$svcMessage", ['$modal', svcMessage]);
Run Code Online (Sandbox Code Playgroud)
除非我们使用新版本的ui-boostrap.模态提供程序现在定义为:
.provider('$uibModal', function() {
var $modalProvider = {
options: {
animation: true,
backdrop: true, //can also be false or 'static'
keyboard: true
},
Run Code Online (Sandbox Code Playgroud)
这里的建议是,一旦我们确保包含依赖项,我们仍然会收到此错误,我们应该检查我们正在使用的JS库的版本.我们还可以快速搜索并查看文件中是否存在该提供程序.
在这种情况下,模态提供者现在应该如下:
app.factory("$svcMessage", ['$uibModal', svcMessage]);
Run Code Online (Sandbox Code Playgroud)
再说一遍.确保您的ui-bootstrap版本支持您当前的angularjs版本.如果没有,您可能会遇到其他错误,如templateProvider.
有关信息,请查看此链接:
http://www.ozkary.com/2016/01/angularjs-unknown-provider-modalprovider.html
希望能帮助到你.
| 归档时间: |
|
| 查看次数: |
87908 次 |
| 最近记录: |