gpt4 book ai didi

javascript - 尝试使用 Angular-gridify 时出现 Angular Injector 错误

转载 作者:行者123 更新时间:2023-11-28 06:57:50 25 4
gpt4 key购买 nike

有一个 jsFiddle here

我正在尝试以类似于 this 的方式使用 angular-gridify ,但我收到如下 $injector 错误。假设这就是问题所在,我应该如何注入(inject) Angular-Gridify 依赖项?

Uncaught Error: [$injector:modulerr] Failed to instantiate module testApp due to:
Error: [$injector:nomod] Module 'testApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

HTML:

<body ng-app="ExampleApp" ng-controller="ExampleCtrl" ng-click="generateTiles()">
<div class="gridify" ng-gridify="{wrapperSelector: '.wrapper', tileSelector: '.tile', perRow: 5, averageRatio: 1.5, gutter: 10, watch: 'tiles'}">
<div class="wrapper">
<div ng-repeat="tile in tiles" class="tile" data-ratio="{{tile.ratio}}" style="background-color: {{tile.color}}">
<img src="{{tile.src}}"></img>
</div>
</div>
</div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.5/angular.min.js"></script>
<script type="text/javascript" src="angular-gridify.js"></script>
<script type="text/javascript" src="app.js"></script>
</body>

JavaScript:

var testApp = angular.module('testApp', ['ngRoute', 'angular-gridify']).config(function() {});
testApp.config(function ($routeProvider, $locationProvider) {
$routeProvider.when('/', {
controller: 'testCtrl'
})
});
testApp.controller('testCtrl', function($scope) {
$scope.tiles = [];

$scope.generateTiles = function() {
for (var i = 0; i < 50; i++) {
var ratio = Math.random() > 0.6 ? 0.661 : 1.511;
$scope.tiles[i] = {
ratio: ratio,
color: '#' + ('000000' + Math.floor(Math.random() * 16777215).toString(16)).slice(-6)
};

}
};

$scope.generateTiles();
});

最佳答案

在你的js中你注册了testCtrl Controller 而不是ExampleCtrl Controller

关于javascript - 尝试使用 Angular-gridify 时出现 Angular Injector 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32426031/

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