gpt4 book ai didi

javascript - 由于 : Error: [$injector:modulerr],无法实例化模块 [模块名称]

转载 作者:行者123 更新时间:2023-11-28 17:58:19 25 4
gpt4 key购买 nike

我在将 moment.js 注入(inject)我的模块 myApp 时遇到问题。我已关注 中的文档https://github.com/urish/angular-moment https://www.npmjs.com/package/angular-momentjs但无济于事。阅读其他类似的问题和答案,很可能是由于语法不正确,但我看不到它。有什么想法吗?

<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular-route.min.js"></script>
<script src="scripts/moment.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script src="scripts/angular-moment.js"></script>
<script src="scripts/app.js"></script>
<小时/>
<main ng-app="myApp" ng-controller="appCtrl">
<div class="container">
<section class="ng-view">

</section>
</div>
</main>
<小时/>
var app = angular.module('myApp', ['ngRoute', 'angularMoment']);

app.controller('transCtrl', ['$scope', '$http', 'moment', function($scope, $http, moment){
$http.get('../json/transactions.json')
.then(function(response){
$scope.transaction = response.data.transactions;
}, function(errResponse){
alert('error');
});

$scope.sortType = 'transId'; // set the default sort type
$scope.sortReverse = false; // set the default sort order
$scope.searchTrans = ''; // set the default search/filter term

$scope.date = new moment();

console.log($scope.date)

}]);

最佳答案

由于您从 scripts 文件夹中包含 moment.jsangular-moment,因此您应该将这两个文件下载到 scripts 中 文件夹并确保您的服务器以static 方式为 scripts 文件夹提供服务(这可以通过检查浏览器的network 标签来确认) .

下面的示例使用在线脚本并且工作正常。

var app = angular.module('myApp', ['ngRoute', 'angularMoment']);

app.controller('transCtrl', ['$scope', '$http', 'moment', function($scope, $http, moment) {
$scope.date = new moment();

console.log($scope.date)

}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular-route.min.js"></script>
<!-- <script src="scripts/moment.js"></script> -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.0/moment.js"></script>
<!-- <script src="scripts/angular-moment.js"></script> -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-moment/1.0.1/angular-moment.js"></script>

<div ng-app="myApp" ng-controller="transCtrl">
<div class="container">

</div>
</div>

关于javascript - 由于 : Error: [$injector:modulerr],无法实例化模块 [模块名称],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44068037/

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