MVC4 after bundling angularjs not working throwing exception

1k Views Asked by At

In my MVC4 application working fine with angularjs and have no errors.if i bundle js and css using

BundleTable.EnableOptimizations = true;

i got uncaught error. http://errors.angularjs.org/1.3.15/$injector/modulerr?p0

enter image description here

Controller.js

App.controller('userController',
  ['$rootScope', '$scope', '$state', 'exDialog', '$stateParams', 'toaster', 'Upload', '$modal',
  function ($rootScope, $scope, $state, exDialog, $stateParams, toaster, Upload, $modal) {

//Logic here

}]);

Solution

the issue is while we do minification. The directive names are changed with single characters for minification.

issue Js finding method

public class NonMinifying : IBundleTransform
    {
        public void Process(BundleContext context, BundleResponse bundle)
        {
            if (bundle == null)
            {
                throw new ArgumentNullException("bundle");
            }

            //context.HttpContext.Response.Cache.SetLastModifiedFromFileDependencies();
            foreach (var file in bundle.Files)
            {
                HttpContext.Current.Response.AddFileDependency(HttpContext.Current.Request.MapPath(file.IncludedVirtualPath));
            }

        }
    }

create the bundle like below code and bundle your js one by one into this.if worked fine change the next js like this i found the issue line.Hope above details will help to find issue line in js

  bundles.Add(new Bundle("~/bundles/appScriptsnonmini", new NonMinifying())
              .IncludeDirectory("~/Scripts/app", "*.js")                     
                );
0

There are 0 best solutions below