简体   繁体   中英

Uglify the javascript files

Do I need to use bracket notation for defining the run() block? If i want to minify the javascript files even though run() block is not expecting the any parameters.

here is my code for run block

  app.run(function () {
  $(function () {
    $(document).keydown(function (e) {
      if((e.which || e.keyCode) == 116 || (e.keyCode == 82 && e.ctrlKey)){
        e.preventDefault();
        var path = $state.current.name;
         var subpath = path.split(".");
         if(subpath.length > 1) {
         if (subpath[1] == 'list')
         $state.reload();
         }else
         $state.reload();
      }else {
        return (e.which || e.keyCode) != 116;
      }
    });
  });
});

any help will be appriciated.

If u are injecting any dependencies u need to do dependency annotation(declare the injection using string) before minifying.

In your case looks like u need inject $state, so u'd better have ur code like:

   app.run(['$state',function ($state) {
  $(function () {
    $(document).keydown(function (e) {
      if((e.which || e.keyCode) == 116 || (e.keyCode == 82 && e.ctrlKey)){
        e.preventDefault();
        var path = $state.current.name;
         var subpath = path.split(".");
         if(subpath.length > 1) {
         if (subpath[1] == 'list')
         $state.reload();
         }else
         $state.reload();
      }else {
        return (e.which || e.keyCode) != 116;
      }
    });
  });
}]);

Then u can uglify it safely.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM