- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
嘿伙计们,当我缩小我的 Angular JS 1 应用程序时,我收到一个错误 Error: $injector:modulerr
,到目前为止,我已经研究过这是我调用依赖项的方式 HomeController
但是我不确定我可能哪里出错了。我注意到这里有一些预先存在的问题,但我找不到解决这个问题的答案。
我感觉对此 Controller 的依赖性可能是问题所在:
function HomeController($http, $firebaseArray, $scope, $scrollArray) {
var vm = this;
var baseRef = new Firebase("https://racoon.firebaseio.com/yello");
vm.feeds = $scrollArray(baseRef, 'date');
vm.config = {
plugins: {
controls: {
autoHide: true,
autoHideTime: 1000
}
}
};
}
因为代码被缩小了,所以我猜测函数中调用的依赖项正在以某种方式被破坏。
所以我尝试像这样在函数下方注入(inject)它们:
HomeController.$inject = ['$http', '$firebaseArray', '$scope', '$scrollArray'];
这里是我的应用程序的所有 JS,以防万一不是这个 Controller 导致了这种情况:
(function() {
'use strict';
angular
.module('thatsPulman', [
// Angular modules.
'ngSanitize',
// Third party modules.
'firebase',
// Custom modules.
'app.core'
])
})();
(function() {
'use strict';
angular.module('app.core', ['iso.directives', 'ngSanitize', 'linkify', 'angular-images-loaded', 'imagesLoaded', 'yaru22.angular-timeago','infinite-scroll','com.2fdevs.videogular', 'com.2fdevs.videogular.plugins.controls', 'com.2fdevs.videogular.plugins.overlayplay'], function($interpolateProvider) {
$interpolateProvider.startSymbol('<%');
$interpolateProvider.endSymbol('%>');
});
})();
(function() {
'use strict';
angular
.module('app.core')
.controller('HomeController', HomeController)
.factory('$scrollArray', scrollArray);
function HomeController($http, $firebaseArray, $scope, $scrollArray) {
var vm = this;
var baseRef = new Firebase("https://racoon.firebaseio.com/yello");
vm.feeds = $scrollArray(baseRef, 'date');
vm.config = {
plugins: {
controls: {
autoHide: true,
autoHideTime: 1000
}
}
};
}
HomeController.$inject = ['$http', '$firebaseArray', '$scope', '$scrollArray'];
function scrollArray($firebaseArray, $timeout) {
return function(baseRef, field) {
// create a special scroll ref
var scrollRef = new Firebase.util.Scroll(baseRef, field);
// generate a synchronized array with the ref
var list = $firebaseArray(scrollRef);
// store the scroll namespace on the array for easy ref
list.scroll = scrollRef.scroll;
list.scroll.next(10);
return list;
}}
})();
(function() {
'use strict';
angular
.module('app.core')
.directive('imagesLoaded', imagesLoaded)
.directive('scroll', scroll);
function imagesLoaded($timeout) {
return {
restrict: 'A',
link: function($scope, $elem, $attr) {
$timeout(function() {
$elem.isotope();
$elem.isotope('once', 'layoutComplete', function(isoInstance, laidOutItems) {
$elem.imagesLoaded(function() {
$elem.isotope('layout');
});
});
}, 0);
}
};
}
function scroll($window) {
return function(scope, element, attrs) {
angular.element($window).bind("scroll", function() {
if (this.pageYOffset >= 300) {
scope.showContent = true;
} else {
scope.showContent = false;
}
scope.$apply();
});
};
};
})();
(function() {
'use strict';
angular
.module('app.core')
.filter('instagramLink', instagramLink);
function instagramLink($filter, $sce) {
return function(text, target) {
if (!text) return text;
var replacedText = $filter('linky')(text, target);
var targetAttr = "";
if (angular.isDefined(target)) {
targetAttr = ' target="' + target + '"';
}
// replace #hashtags
var replacePattern1 = /(^|\s)#(\w*[a-zA-Z_]+\w*)/gim;
replacedText = replacedText.replace(replacePattern1, '$1<a href="https://www.instagram.com/explore/tags/$2"' + targetAttr + '>#$2</a>');
$sce.trustAsHtml(replacedText);
return replacedText;
};
};
})();
知道我哪里可能出错吗?谢谢
最佳答案
缩小破坏了代码,因为您正在使用 Implicit Annotation用于依赖注入(inject)。
Implicit Annotation
Careful: If you plan to minify your code, your service names will get renamed and break your app.
像ng-annotate这样的工具让您在应用程序中使用隐式依赖注释,并在缩小之前自动添加内联数组注释。如果您决定采用这种方法,您可能需要使用
ng-strict-di
.由于这些注意事项,我们建议避免这种注释风格。
关于javascript - AngularJS错误: $injector:modulerr after being minified,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38125849/
我的 js 文件中有这样的行 console.log('FunctionName()'); 默认的 Ajax Minifier 设置不会从 .min.js 输出中删除这些行。 我在这个讨论中注意到一个
我使用 uglifyJS 缩小了 Javascript 和 CSS 文件,磁盘上的文件大小已大大减小。但在使用 Chrome 开发者工具检查网络选项卡中加载资源的总时间时,我发现没有区别。那么缩小真的
我正在探索将单个流文件传输到自定义处理器中的两个或多个关系的选项,我在文档中没有找到任何帮助,NIFI 支持此功能吗? 示例代码: session.transfer(flowFile, REL_SUC
我有一个 JS 文件,我正试图缩小它,但它遇到了一些问题。这是文件: $(document).ready(function () { function DisplayMessage(message,
我能找到的几乎所有 CSS 压缩器基本上都是去除空格的正则表达式。有没有更聪明的 CSS 压缩器?比如合并相似的选择器/属性等? 最佳答案 您可以在 Google 上搜索“CSS 优化器”或“CSS
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 8 年前。 Improv
我正在使用这个压缩器: #!/usr/bin/perl use Getopt::Std; use strict; my %opts; getopts('f:t:h', \%opts) || usage
我正在尝试编写一个可用于根据文件类型缩小 html、css 和 js 的 minify 函数。我想将现有的 gulp 插件用于这 3 个缩小过程来进行实际的缩小。我遇到的问题是我不知道如何在单个黑胶唱
我正在努力成为一个好男孩,并且用口香糖最小化我的css。我目前正在使用gulp-sass(不是gulp-ruby-sass),它似乎没有内置的缩小功能。所以现在我正在使用gulp-minify-css
我想使用 Laravel Elixir 来缩小我的 css/files 文件。但我不想使用混合方法并将它们合并。我想要的只是从我原来的“custom.js”生成一个“custom.min.js”文件。
有没有办法告诉 UglifyJS 跳过特定的代码部分,也许使用这样的注释: // uglifyjs:skipStart filter = function(item){ /* some crazy f
我是 jquery 新手,我可以用它进行简单的编码。我想更多地了解这些文件“缩小”“未压缩”以及何时应该使用每个文件? 最佳答案 每个文件的缩小版本和压缩版本只是在具有相同功能的情况下缩小尺寸的版本。
可以在不添加 -min 后缀的情况下缩小 js 文件吗? 我想保留原来的名字。 gulp.task("js-external-release", function() { gulp.src(c
在 page1.html 上说我需要 mootools.js 和 main.js ......我猜这些工具应该生成一个缩小的 js 文件(比如 min1.js)。 然后在 page2.html 我需要
我最近从 require.js 迁移到 webpack,并且一些 node_module 内置了 .min 文件。当我使用 node_module 中的文件时,我只做 require('my-modu
我正在使用 libman.json 将客户端库从 cdnjs 拉到我项目的一个文件夹中。然后我想将这些库捆绑并缩小到一个 js 文件中,该文件将在 Web 应用程序中部署和引用。为此,我使用了一个名为
我下载了 cordova-minify 插件,它可以压缩我的 Cordova 应用程序 javascript 代码。我尝试运行命令: cordova build browser 我明白了 cordov
我正在构建一个 angular2 应用程序,并开始进行我的构建/缩小过程。我可以使用未缩小的单个 JS 文件在开发模式下成功构建和运行我的应用程序。但是,当我将它们构建为单个串联文件时,我的应用程序将
Minify对我来说工作正常,但在更改其中一个源文件后,我收到一个空白页面。刷新页面不会改变任何东西。没有缓存的刷新(Strg + F5)解决了这个问题。在没有缓存的情况下刷新一次后,我可以返回使用缓
我经常看到“缩小”这个词,但我似乎从未选择过“缩小”的脚本(即来自 jQuery 插件),但我想我应该这样做。如果我是对的,缩小意味着在不改变其功能的情况下从源代码中删除所有不必要的东西,那么为什么我
我是一名优秀的程序员,十分优秀!