使用 'use strict' 后,该指令无效

After using 'use strict' this directive is not working

使用 'use restrict' 后,此指令无效。

它甚至在使用功能后都没有命中并且'use strict'它不起作用

(function () {
    "use strict";
    var appRoot = angular.module("app.top").directive('confirmOnExit', ['$location', 'ConfirmModal', '$timeout', function (location, ConfirmModal, $timeout) {

        return {
            link: function ($scope, element, attrs) {
                $scope.$evalAsync(function () {
                    var unbindChangeSuccess = $scope.$on('$locationChangeStart', function (event, next, current, e) {
                        $scope.DirtyForm = ($scope.componentAddForm.$dirty ? $scope.componentAddForm.$dirty : $scope.resourceForm.$dirty)
                        if ($scope.DirtyForm) {
                            event.preventDefault();
                            alert('Route Changed')                         
                        } else {
                        };
                    });

                })
            }
        };
    }]);
})

需要是自调用函数:

(function () {
    var appRoot = angular.module("app.top").directive('confirmOnExit', ['$location', 'ConfirmModal', '$timeout', function (location, ConfirmModal, $timeout) {

        return {
            link: function ($scope, element, attrs) {
                $scope.$evalAsync(function () {
                    var unbindChangeSuccess = $scope.$on('$locationChangeStart', function (event, next, current, e) {
                        $scope.DirtyForm = ($scope.componentAddForm.$dirty ? $scope.componentAddForm.$dirty : $scope.resourceForm.$dirty)
                        if ($scope.DirtyForm) {
                            event.preventDefault();
                            alert('Route Changed')                         
                        } else {
                        };
                    });

                })
            }
        };
    }]);
})();

有关详细信息,请查看 THIS post。