gpt4 book ai didi

javascript - angularjs 无法实例化模块 ui.bootstrap.demo

转载 作者:行者123 更新时间:2023-11-27 22:53:49 25 4
gpt4 key购买 nike

我正在学习 AngularJS,但我陷入了困境。我不断收到错误

 ncaught Error: [$injector:modulerr] Failed to instantiate module ui.bootstrap.demo due to:
Error: [$injector:nomod] Module 'ui.bootstrap.demo' is not available!

下面是我的 html 文件

<html ng-app="ui.bootstrap.demo">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular-animate.js"></script>
<script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-1.3.3.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<script src="https://rawgit.com/esvit/ng-table/master/dist/ng-table.min.js"></script>
<script src="resources/js/main.js"/>
<script src="resources/js/gsenv.js"/>
<script src="resources/js/CarouselController.js"/>
</head>

但是,如果我不在单独的文件中编写 JavaScript,它就会按执行方式运行

<script type="text/javascript">
angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('CarouselDemoCtrl', function ($scope, $http, dataShare) {
$scope.myInterval = 5000;
$scope.noWrapSlides = false;
$scope.active = 0;
var slides = $scope.slides = [];
var currIndex = 0;

$scope.sendEnvName = function(data) {
dataShare.sendEnvNameDetails(data);
}

$scope.addSlide = function (envName) {
slides.push({
text: envName,
id: currIndex++
});
};

$http.get("http://localhost:8080/getEnvList")
.success(function (data) {
for (var i in data) {
$scope.addSlide(data[i].envName);
}
});

});

这样工作正常,无法理解可能是什么问题

main.js

var app = angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap', 'ngTable']);

jsenv.js

app.factory('dataShare',function($rootScope){
var service = {};
service.envName = 'no-env'
service.sendEnvNameDetails = function(data){
console.log(data)
this.envName = data;
$rootScope.$broadcast('data_shared');
};
service.getData = function(){
return this.envName;
};
return service;
});

轮播

app.controller('CarouselDemoCtrl', function ($scope, $http, dataShare) {
$scope.myInterval = 5000;
$scope.noWrapSlides = false;
$scope.active = 0;
var slides = $scope.slides = [];
var currIndex = 0;

$scope.sendEnvName = function(data) {
dataShare.sendEnvNameDetails(data);
}

$scope.addSlide = function (envName) {
slides.push({
text: envName,
id: currIndex++
});
};

$http.get("http://localhost:8080/getEnvList")
.success(function (data) {
for (var i in data) {
$scope.addSlide(data[i].envName);
}
});

});

最佳答案

更改您的 Controller 和工厂:
来自:

app.controller('CarouselDemoCtrl', function ($scope, $http, dataShare) { });

致:

angular.module('ui.bootstrap.demo').controller('CarouselDemoCtrl', function ($scope, $http, dataShare) { });

来自:

app.factory('dataShare',function($rootScope){});

致:

angular.module.factory('dataShare',function($rootScope){});

关于javascript - angularjs 无法实例化模块 ui.bootstrap.demo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37797574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com