Angular module()。factory()不是concat(gulp)之后的函数, [英] Angular module().factory() is not a function after concat (gulp)

查看:167
本文介绍了Angular module()。factory()不是concat(gulp)之后的函数,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去的几个小时里试图用 gulp 来连接/丑化我的 angular 应用程序,我已经把整个进程转换为简单的concat,甚至将concat进程中的角度文件从头文件中移除到单独的< script> 请求中 - 仍然收到相同的错误:


$ b

未捕获的TypeError:angular.module(...)。factory(...)不是函数





 <$ 
$ b


$ b

没有concat一切都很好。

c $ c> gulp.task('JS',function(){
gulp.src(['!_ dependencies / angular.min.js','_dependencies / jquery.min.js','_dependencies / moment .min.js','Alpha / _lilhelpers.js','Alpha / routes.js','!trainerreg.js','** / *。js'],{cwd:'./public/scripts'} )
.pipe(concat('concat.js'))
.pipe(gulp.dest('./ public / min'));
});

似乎Error basicaly会立即发生 .factory

下面是它当前停止的错误行 - 它是一个缩小的代码,但我没有缩小它,我只是拼凑文件现在包括 angular-animate.min ,从这行代码(实际上是第一个)。

如果我删除 angular-animate 它只会在其他工厂抛出错误。

 (function(N,f,W){'use strict'; f.module(ngAnimate,[ng])。directive(ngAnimateChildren,function(){return function(X,r,g) {G = g.ngAnimateChildren; f.isString(G)及;&安培; 0 === g.length r.data( $$ ngAnimateChildren 0!):$ X.手表(G,函数(f) ($$ animateReflow,[$$ rAF,$ document,function(f,r){var g){r.data($$ ngAnimateChildren,!! f)})}} = r [0] .body; return function(r){return f(function(){r(g.offsetWidth)})}}])。config ... 

UPDAT E :哦,我错了,只要遇到问题,它就不会中断;只要它遇到了,就会中断。在经过精简的部分文件中有工厂...



很高兴听到任何解决方案/假设!

解决方案



Chrome浏览器指向错误的行,Firefox帮助我位。错误本身让我感到困惑,只是在一段时间后我明白了 angular.module(...)。factory(...)并不意味着。工厂是未定义的,但是正在发生一些试图通过工厂值作为函数返回的调用,例如 .factory(...)()。今天我终于明白了原因。
在我的一个工厂之后,有一些第三方代码(在这种情况下是角动画),并且像往常一样封装在闭包中,但事实是,我的工厂没有; code>在最后,所以在concat后我有:

  .factory('fact',function(){my ()函数(args){第三方代码})()

由于包含工厂的行并未以分号结尾,因此封闭环绕被解释为函数调用。这个问题没有出现没有concat,因为这个模块是在一个单独的文件。



课程 - 不要忘记我们的同事; ;)


Trying to concat/uglify my angular app using gulp for the last few hours, i have stripped down whole process to simple concat, and even removed angular file from concat process to a separate <script> request in header - and still, I receive the same error:

Uncaught TypeError: angular.module(...).factory(...) is not a function

Without concat everything is fine.

My gulp task:

gulp.task('JS', function() {
  gulp.src(['!_dependencies/angular.min.js', '_dependencies/jquery.min.js', '_dependencies/moment.min.js', 'Alpha/_lilhelpers.js', 'Alpha/routes.js' , '!trainerreg.js', '**/*.js'], {cwd: './public/scripts'})         
    .pipe(concat('concat.js'))    
    .pipe(gulp.dest('./public/min'));
});

It seems that Error basicaly happends as soon as .factory appears in code.

Here is the line on which it currently stops with error - it is a minified code, yet i am not minifiying it, im just concating files right now including angular-animate.min from which this line of code (1st one in fact).
And if I remove angular-animate it will just throw error on another factory that will be on the way.

(function(N,f,W){'use strict';f.module("ngAnimate",["ng"]).directive("ngAnimateChildren",function(){return function(X,r,g){g=g.ngAnimateChildren;f.isString(g)&&0===g.length?r.data("$$ngAnimateChildren",!0):X.$watch(g,function(f){r.data("$$ngAnimateChildren",!!f)})}}).factory("$$animateReflow",["$$rAF","$document",function(f,r){var g=r[0].body;return function(r){return f(function(){r(g.offsetWidth)})}}]).config...

UPDATE: Oh, I was mistaken, it's NOT breaking as soon as .factory met; it breaks as soon as it meets .factory in minified part of concated file...

Will be happy to hear any solutions/assumptions!

解决方案

I've found it!
Chrome was pointing to a wrong line, Firefox helped me a bit. Error itself confused me, only after some time I understood that angular.module(...).factory(...) means not that .factory is undefined but rather that something trying to invoke returned by factory value as a function i.e .factory(...)() is happening. Today I finally figured out what was the cause. Right after one of my factories there was some 3rd party code (angular animate in this case) and it was wrapped in closure as usual, but the thing is, my factory had no ; at the end so after concat I had:

.factory('fact', function(){my-factory-code}) (function(args){3rd-party-code})()

Wrapping around closure was interpreted as function invocation due to a fact that line with factory wasn't terminated by semicolon. And this problem was not showing up without concat, as this module was in a separate file.

Lesson - don't forget our fellow ; ;)

这篇关于Angular module()。factory()不是concat(gulp)之后的函数,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆