如何选择触发顺序

时间:2018-03-20 13:43:09

标签: angularjs events click openlayers-3

我有这个指令:

module.directive("myDirective", function() {
    return {
        restrict: 'E',
        templateUrl: 'pathToUrl',
        controller: myCtrl,
        controllerAs: vm,
        bindToController: true,
        scope: {
            flag: '=',
            toggleFlagFunc: '='
        }
    }

    function myCtrl() {
        let vm = this;
        vm.olMap = new ol.Map({/*map init here*/})
        vm.olMap.on("click", clickFunc);

        function clickFunc() {
            if (vm.flag) {
                // Do some logic
                vm.toggleFlagFunc();
            }
        }
    }
}

这是模板网址:

<div class="first-div"></div>
<div class="second-div"></div>
<div class="map-container-div"></div>
<div class="third-div"></div>

这个例子:

<my-directive flag="vm.flag" toogle-flag-func="vm.toogleFlagFunc" ng-click="vm.myDirectiveClicked()"></my-directive>

这是父ctrl:

function parentCtrl {
    let vm = this;
    vm.flag = false; // The flag changed to true somewhere
    vm.toggleFlagFunc = () => {
        vm.flag = !vm.flag;
        // Some Other Logic
    }

    vm.myDirectiveClicked = () => {
        if (!vm.flag) {
            // Do some logic here
        }
    }
}

我的问题是当vm.flag评估为true并点击map-container-div时,被调用函数的顺序为vm.toogleFlagFunc,然后是vm.myDirectiveClicked

我可以改变订单吗?

提前致谢!

0 个答案:

没有答案