使用'使用严格'这个指令不起作用

时间:2017-09-09 07:58:13

标签: angularjs angularjs-directive

使用'使用限制'该指令无效。

使用功能后甚至没有打击,并且使用严格的'它无法正常工作

(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 {
                        };
                    });

                })
            }
        };
    }]);
})

1 个答案:

答案 0 :(得分:1)

它需要是一个自我调用函数:

(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帖子。