这是什么错误:[$喷油器:unpr]未知提供商:tProvider< - T< - myActiveLinkDirective是什么意思? [英] What does Error: [$injector:unpr] Unknown provider: tProvider <- t <- myActiveLinkDirective mean?

查看:312
本文介绍了这是什么错误:[$喷油器:unpr]未知提供商:tProvider< - T< - myActiveLinkDirective是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我的测试,看看我的应用程序的版本PROD如何期待;我继续通过一些一饮而尽任务来运行它(缩小,不用带CSS等),并得到这个错误:

Basically I am testing to see how a PROD version of my app is looking; I proceeded to run it through some gulp tasks (minify, strip unused css etc.) and got this error:

 Error: [$injector:unpr] Unknown provider: tProvider <- t <- myActiveLinkDirective

谁能什么是怎么回事帮助?

Can anyone help with what's going on here?

这是我的一些棱角code:

This is some my angular code:

  var rustyApp = angular.module('rustyApp', [
    'ngAnimate',
    'ngRoute',
    'viewController',
    'mm.foundation',
    'angular-flexslider',
    'ui.router']).config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
          $routeProvider.when('/', {
        title: 'home',
        templateUrl: '/partials/home.html',
        controller: 'HomeController'
    }).when('/work', {
        title: 'my work',
        templateUrl: '/partials/work.html',
        controller: 'WorkController'
    }).when('/contact', {
        title: 'contact',
        templateUrl: '/partials/contact.html',
        controller: 'ContactController'
    }).otherwise({redirectTo: '/'});
    // configure html5 to get links working

    $locationProvider.html5Mode(true);

    }]);




     rustyApp.controller('BasicSliderCtrl', function($scope) {
        $scope.slides = [
           '../images/sliderContent/1.jpg',
           '../images/sliderContent/2.jpg',
           '../images/sliderContent/3.jpg',
           '../images/sliderContent/4.jpg'
        ];

     });

     rustyApp.run(function() {
        FastClick.attach(document.body);
     });

    rustyApp.run(['$location', '$rootScope', function($location, $rootScope) {
        $rootScope.$on('$routeChangeSuccess', function(event, current, previous) {
            $rootScope.title = current.$$route.title;
        });
    }]);


    rustyApp.controller('HomeController', function($scope) {
        $scope.pageClass = 'home';
    });
    rustyApp.controller('WorkController', function($scope) {
        $scope.pageClass = 'work';
    });
    rustyApp.controller('ContactController', function($scope) {
        $scope.pageClass = 'contact';
    });

    rustyApp.controller('OffCanvasDemoCtrl', function($scope) {});


    var OffCanvasDemoCtrl = function($scope) {};

    rustyApp.controller('ContactController', function($scope, $http) {
    $scope.result = 'hidden'
    $scope.resultMessage;
    $scope.formData; //formData is an object holding the name, email, subject, and message
    $scope.submitButtonDisabled = false;
    $scope.submitted = false; //used so that form errors are shown only after the form has been submitted
    $scope.submit = function(contactform) {
        $scope.submitted = true;
        $scope.submitButtonDisabled = true;
        if (contactform.$valid) {
            $http({
                method: 'POST',
                url: '../partials/mailer.php',
                data: $.param($scope.formData), //param method from jQuery
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                } //set the headers so angular passing info as form data (not request payload)
            }).success(function(data) {
                console.log(data);
                if (data.success) { //success comes from the return json object
                    $scope.submitButtonDisabled = true;
                    $scope.resultMessage = data.message;
                    $scope.result = 'bg-success';
                    if ($scope.result === 'bg-success') {
                        $scope.class = "bg-success";
                    }
                    // if($scope.result){setTimeout(window.location.reload(true),4000);}
                    if ($scope.result) {
                        setTimeout(function() {
                            window.location.reload(true)
                        }, 4000);
                    }
                } else {
                    $scope.submitButtonDisabled = false;
                    $scope.resultMessage = data.message;
                    $scope.result = 'bg-danger';
                }
            });
        } else {
            $scope.submitButtonDisabled = false;
            if ($scope.submitButtonDisabled) {
                $scope.class = "bg-danger";
            }
            $scope.resultMessage = 'Failed Please fill out all the fields.';
            $scope.result = 'bg-danger';
        }
    }
});

var viewController = angular.module('viewController', []);

rustyApp.directive('myActiveLink', function($location) {
    return {
        restrict: 'A',
        scope: {
            path: "@myActiveLink"
        },
        link: function(scope, element, attributes) {
            scope.$on('$locationChangeSuccess', function() {
                if ($location.path() === scope.path) {
                    element.addClass('uk-active');
                } else {
                    element.removeClass('uk-active');
                }
            });
        }
    };
});
// var $j = jQuery.noConflict();

// $j(function() {
//     $j('#Container').mixItUp();

// });

    rustyApp.directive('mixItUp', function() {
        var directive = {
            restrict: 'A',
            link: link
        };

        return directive;

        function link(scope, element, attrs) {
            var $j = jQuery.noConflict();
            var mixContainer = $j('#Container');
            mixContainer.mixItUp();
            mixContainer.on('$destroy', function() {
                mixContainer.mixItUp('destroy');
            });

        }
    });


    rustyApp.directive('share', function() {
        var directive = {
            restrict: 'A',
            link: link
        };

        return directive;

        function link(scope, element, attrs) {
            var $s = jQuery.noConflict();
            // mixContainer.on('$destroy', function() {
            //     mixContainer.mixItUp('destroy');
            // });
        var $s = new Share(".share-button", {
          networks: {
            facebook: {
              app_id: "602752456409826",
            }
          }
        });

        }
    });

    rustyApp.directive('animationOverlay', function() {
        var directive = {
            restrict: 'A',
            link: link
        };

        return directive;

        function link(scope, element, attrs) {
            var modal = $.UIkit.modal(".modalSelector");

            if (modal.isActive()) {
                modal.hide();
            } else {
                modal.show();
            }

        }
    });

修订code

    var rustyApp = angular.module('rustyApp', [
    'ngAnimate',
    'ngRoute',
    'viewController',
    'mm.foundation',
    'angular-flexslider',
    'ui.router'
]).config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
    $routeProvider.when('/', {
        title: 'home',
        templateUrl: '/partials/home.html',
        controller: 'HomeController'
    }).when('/work', {
        title: 'my work',
        templateUrl: '/partials/work.html',
        controller: 'WorkController'
    }).when('/contact', {
        title: 'contact',
        templateUrl: '/partials/contact.html',
        controller: 'ContactController'
    }).otherwise({redirectTo: '/'});
    // configure html5 to get links working

    $locationProvider.html5Mode(true);

}]);


 rustyApp.controller('BasicSliderCtrl', ['$scope', 
    function($scope) {
    $scope.slides = [
        '../images/sliderContent/1.jpg',
        '../images/sliderContent/2.jpg',
        '../images/sliderContent/3.jpg',
        '../images/sliderContent/4.jpg'
    ];

}]);


rustyApp.run(function() {
    FastClick.attach(document.body);
  });

rustyApp.run(['$location', '$rootScope', function($location, $rootScope) {
    $rootScope.$on('$routeChangeSuccess', function(event, current, previous) {
        $rootScope.title = current.$$route.title;
    });
}]);


rustyApp.controller('HomeController', ['$scope', function($scope) {
     $scope.pageClass = 'home';
}]);
rustyApp.controller('WorkController', ['$scope', function($scope) {
     $scope.pageClass = 'work';
}]);
rustyApp.controller('ContactController', ['$scope', function($scope) {
     $scope.pageClass = 'contact';
}]);
rustyApp.controller('OffCanvasDemoCtrl', ['$scope', function($scope) {}]);


var OffCanvasDemoCtrl = function($scope) {};

rustyApp.controller('ContactController', ['$scope', function($scope, $http) {
    $scope.result = 'hidden'
    $scope.resultMessage;
    $scope.formData; //formData is an object holding the name, email, subject, and message
    $scope.submitButtonDisabled = false;
    $scope.submitted = false; //used so that form errors are shown only after the form has been submitted
    $scope.submit = function(contactform) {
        $scope.submitted = true;
        $scope.submitButtonDisabled = true;
        if (contactform.$valid) {
            $http({
                method: 'POST',
                url: '../partials/mailer.php',
                data: $.param($scope.formData), //param method from jQuery
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded'
                } //set the headers so angular passing info as form data (not request payload)
            }).success(function(data) {
                console.log(data);
                if (data.success) { //success comes from the return json object
                    $scope.submitButtonDisabled = true;
                    $scope.resultMessage = data.message;
                    $scope.result = 'bg-success';
                    if ($scope.result === 'bg-success') {
                        $scope.class = "bg-success";
                    }
                    // if($scope.result){setTimeout(window.location.reload(true),4000);}
                    if ($scope.result) {
                        setTimeout(function() {
                            window.location.reload(true)
                        }, 4000);
                    }
                } else {
                    $scope.submitButtonDisabled = false;
                    $scope.resultMessage = data.message;
                    $scope.result = 'bg-danger';
                }
            });
        } else {
            $scope.submitButtonDisabled = false;
            if ($scope.submitButtonDisabled) {
                $scope.class = "bg-danger";
            }
            $scope.resultMessage = 'Failed Please fill out all the fields.';
            $scope.result = 'bg-danger';
        }
    }
}]);

var viewController = angular.module('viewController', []);

rustyApp.directive('myActiveLink', ['$location', function($location) {
    return {
        restrict: 'A',
        scope: {
            path: "@myActiveLink"
        },
        link: function(scope, element, attributes) {
            scope.$on('$locationChangeSuccess', function() {
                if ($location.path() === scope.path) {
                    element.addClass('uk-active');
                } else {
                    element.removeClass('uk-active');
                }
            });
        }
    };
}]);
// var $j = jQuery.noConflict();

// $j(function() {
//     $j('#Container').mixItUp();

// });

rustyApp.directive('mixItUp', function() {
    var directive = {
        restrict: 'A',
        link: link
    };

    return directive;

    function link(scope, element, attrs) {
        var $j = jQuery.noConflict();
        var mixContainer = $j('#Container');
        mixContainer.mixItUp();
        mixContainer.on('$destroy', function() {
            mixContainer.mixItUp('destroy');
        });

    }
});


rustyApp.directive('share', function() {
    var directive = {
        restrict: 'A',
        link: link
    };

    return directive;

    function link(scope, element, attrs) {
        var $s = jQuery.noConflict();
        // mixContainer.on('$destroy', function() {
        //     mixContainer.mixItUp('destroy');
        // });
    var $s = new Share(".share-button", {
      networks: {
        facebook: {
          app_id: "602752456409826",
        }
      }
    });

    }
});

rustyApp.directive('animationOverlay', function() {
    var directive = {
        restrict: 'A',
        link: link
    };

    return directive;

    function link(scope, element, attrs) {
        var modal = $.UIkit.modal(".modalSelector");

        if (modal.isActive()) {
            modal.hide();
        } else {
            modal.show();
        }

    }
});

更新

所以我伤口使用一饮而尽-NG-注释,它似乎增加这是语法下面:)建议然而,当我尝试PROD构建我没有得到任何错误或任何东西,它只是静静地失败。谁能帮助?

So I wound using gulp-ng-annotateand it appears to add the syntax which was suggested below :) However when I try a PROD build I don't get any errors or anything, it just fails silently. Can anyone help?

推荐答案

我下面贴之前,我有机会看到$ C $其余c您张贴的通用的答案。是的,的确有一些控制器和指令,使用推论。更改code使用内联注释,在 $注射财产;或更少侵入,使用像 NG-注释(感谢@deitch为指针)的工具。

I posted the generic answer below before I had a chance to see the rest of the code you posted. Yes, indeed you have some controllers and directives that use inference. Change your code to use inline annotation, the $inject property; or less intrusively, use a tool like ng-annotate (thanks @deitch for the pointer).

如果你与缩小你的code,不要使用依赖注释的推理风格。使用 $注属性或使用内联注释。见<一href=\"https://docs.angularjs.org/api/auto/service/$injector\">https://docs.angularjs.org/api/auto/service/$injector.

If you're minifying your code, don't use the inference style of dependency annotation. Use the $inject property or use inline annotation. See https://docs.angularjs.org/api/auto/service/$injector.

不要依靠推断:

function ($scope, $timeout, myFooService) {
}

使用内联注释:

[ '$scope', '$timeout', 'myFooService', function ($scope, $rootScope, myFooService) {
}]

$注属性:

function MyFactory($scope, $timeout, myFooService) {
}

MyFactory.$inject = [ '$scope', '$timeout', 'myFooService' ];

这是因为推理味道依赖于函数的自变量名称为preserved(和匹配,以现有的服务)。你可能会缩小期间失去了原来的名称。

This is because the inference flavour relies on the argument names of the function to be preserved (and match to existing services). You might be losing the original names during minification.

这篇关于这是什么错误:[$喷油器:unpr]未知提供商:tProvider&LT; - T&LT; - myActiveLinkDirective是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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