用Gulp缩小后,ui-router无法正常工作

时间:2016-06-13 04:19:45

标签: angularjs angular-ui-router minify

我使用Angular制作应用并使用Gulp缩小所有文件css,javascript。但是如果我运行gulp build来缩小然后在dist文件夹中运行文件'index.html',ui-router就不会加载模板。在文件html中,标记仍然是这样的:<a ui-sref='link'> LINK </a>。你有点帮助我! 这是链接代码:

app.js https://gist.github.com/quyen91/d4ca009bb0be0e42a5a9dbded76ec45a

gulpfile.js https://gist.github.com/quyen91/bd04688302847a964e16586f9b468d29

错误:https://cdn.pbrd.co/images/1EjGpl8T.png

2 个答案:

答案 0 :(得分:2)

Ui路由器和许多工厂通常会停止工作,因为当我们不缩小时,我们总是将其提供者的正确名称注入控制器或配置或运行或其他任何东西的参数。但是当缩小时,会发生什么是

override func hitTest(point: CGPoint, withEvent event: UIEvent?) -> UIView? {
    if(!self.clipsToBounds && !self.hidden && self.alpha>0){
        for subview in self.subviews.reverse(){
            let subPoint = subview.convertPoint(point, toView: self)
            let result = subview.hitTest(subPoint, withEvent: event)
            if result != nil{
                return result
            }
        }
    }

    return nil
}

这会导致问题..

因此,分别编写提供者名称始终是一种好习惯。 因此功能变为

run(function($state,$rootScope,$http){})
would become 
run(function(x,y,z){})

但是这里变量的提供者是正确的,所以它不会导致任何错误。

在你的情况下,run方法应该是

run(['$state','$rootScope','$http',function($state,$rootScope,$http){}]);
to 
run(['$state','$rootScope','$http',function(x,y,z){}]);

配置应该以

开头
.run(['$rootScope', '$state', 'auth', 'jwtHelper', '$location', 'store',function($rootScope, $state, auth, jwtHelper, $location, store) {


    $rootScope.$on('$locationChangeStart', function() {
    // Get the JWT that is saved in local storage
    // and if it is there, check whether it is expired.
    // If it isn't, set the user's auth state
    var token = store.get('token');
    if (token) {
      if (!jwtHelper.isTokenExpired(token)) {
        if (!auth.isAuthenticated) {
          auth.authenticate(store.get('profile'), token);
        }
      }
    }
    else {
      // Otherwise, redirect to the home route
      $location.path('/about');
    }
  });

答案 1 :(得分:0)

您的.run.config阻止不是缩小安全。

.run

试试这个
.run(['$rootScope', '$state', 'auth', 'jwtHelper', '$location', 'store', function($rootScope, $state, auth, jwtHelper, $location, store) {


    $rootScope.$on('$locationChangeStart', function() {
    // Get the JWT that is saved in local storage
    // and if it is there, check whether it is expired.
    // If it isn't, set the user's auth state
    var token = store.get('token');
    if (token) {
      if (!jwtHelper.isTokenExpired(token)) {
        if (!auth.isAuthenticated) {
          auth.authenticate(store.get('profile'), token);
        }
      }
    }
    else {
      // Otherwise, redirect to the home route
      $location.path('/about');
    }
  });

}]);

config执行相同操作。