• <small id='Ih8eB'></small><noframes id='Ih8eB'>

    • <bdo id='Ih8eB'></bdo><ul id='Ih8eB'></ul>

      1. <tfoot id='Ih8eB'></tfoot>
        <i id='Ih8eB'><tr id='Ih8eB'><dt id='Ih8eB'><q id='Ih8eB'><span id='Ih8eB'><b id='Ih8eB'><form id='Ih8eB'><ins id='Ih8eB'></ins><ul id='Ih8eB'></ul><sub id='Ih8eB'></sub></form><legend id='Ih8eB'></legend><bdo id='Ih8eB'><pre id='Ih8eB'><center id='Ih8eB'></center></pre></bdo></b><th id='Ih8eB'></th></span></q></dt></tr></i><div id='Ih8eB'><tfoot id='Ih8eB'></tfoot><dl id='Ih8eB'><fieldset id='Ih8eB'></fieldset></dl></div>
        <legend id='Ih8eB'><style id='Ih8eB'><dir id='Ih8eB'><q id='Ih8eB'></q></dir></style></legend>

        如何实现“ui-sref"?有条件地执行?

        How to achieve that quot;ui-srefquot; be conditionally executed?(如何实现“ui-sref?有条件地执行?)
          <bdo id='mLQTU'></bdo><ul id='mLQTU'></ul>

            <legend id='mLQTU'><style id='mLQTU'><dir id='mLQTU'><q id='mLQTU'></q></dir></style></legend>
            • <i id='mLQTU'><tr id='mLQTU'><dt id='mLQTU'><q id='mLQTU'><span id='mLQTU'><b id='mLQTU'><form id='mLQTU'><ins id='mLQTU'></ins><ul id='mLQTU'></ul><sub id='mLQTU'></sub></form><legend id='mLQTU'></legend><bdo id='mLQTU'><pre id='mLQTU'><center id='mLQTU'></center></pre></bdo></b><th id='mLQTU'></th></span></q></dt></tr></i><div id='mLQTU'><tfoot id='mLQTU'></tfoot><dl id='mLQTU'><fieldset id='mLQTU'></fieldset></dl></div>

              • <tfoot id='mLQTU'></tfoot>
                  <tbody id='mLQTU'></tbody>

                  <small id='mLQTU'></small><noframes id='mLQTU'>

                1. 本文介绍了如何实现“ui-sref"?有条件地执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  I want to validate certain condition before the browser follow the link dynamically created by ui-router.

                  I was looking into $rootscope.$on('$stateChangeStart', ..) but I have no access to the controller.$scope from there. I also need to use this in several places in the application and would be cumbersome.

                  Keep in mind that ui-sref is linked to ui-sref-active (work together), so i can't remove ui-sref and, by say, to use $state.$go('some-state') inside a function called with ng-click.

                  The condition should be evaluated inside a $scope function and on on-click event (before-transition with the ability to cancel it)

                  I need something like this:

                  <li ui-sref-active="active">
                        <a ui-sref="somestate" ui-sref-if="model.validate()">Go Somestate</a>
                  </li>
                  

                  I tried:

                  <li ui-sref-active="active">
                        <a ui-sref="somestate" ng-click="$event.preventDefault()">Go Somestate</a>
                  </li>
                  
                  <li ui-sref-active="active">
                        <a ui-sref="somestate" ng-click="$event.stopImmediatePropagation()">Go Somestate</a>
                  </li>
                  

                  And

                  <li ui-sref-active="active">
                      <a ui-sref="somestate">
                         <span ng-click="$event.stopPropagation();">Go Somestate</span>
                      </a>
                  </li>
                  

                  Even

                  <li ui-sref-active="active">
                        <a ui-sref="somestate" onclick="return false;">Go Somestate</a>
                  </li>
                  

                  But does not work.

                  SANDBOX

                  解决方案

                  This answer inspired me to create a directive that allows me to interrupt the chain of events that end up changing state. For convenience and other uses also prevents the execution of ng-click on the same element.

                  javascript

                  module.directive('eatClickIf', ['$parse', '$rootScope',
                    function($parse, $rootScope) {
                      return {
                        // this ensure eatClickIf be compiled before ngClick
                        priority: 100,
                        restrict: 'A',
                        compile: function($element, attr) {
                          var fn = $parse(attr.eatClickIf);
                          return {
                            pre: function link(scope, element) {
                              var eventName = 'click';
                              element.on(eventName, function(event) {
                                var callback = function() {
                                  if (fn(scope, {$event: event})) {
                                    // prevents ng-click to be executed
                                    event.stopImmediatePropagation();
                                    // prevents href 
                                    event.preventDefault();
                                    return false;
                                  }
                                };
                                if ($rootScope.$$phase) {
                                  scope.$evalAsync(callback);
                                } else {
                                  scope.$apply(callback);
                                }
                              });
                            },
                            post: function() {}
                          }
                        }
                      }
                    }
                  ]);
                  

                  html

                  <li ui-sref-active="active">
                        <a ui-sref="somestate" eat-click-if="!model.isValid()">Go Somestate</a>
                  </li>
                  

                  PLUNKER

                  这篇关于如何实现“ui-sref"?有条件地执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                  问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)
                  getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)
                    <bdo id='cNY3z'></bdo><ul id='cNY3z'></ul>
                    <i id='cNY3z'><tr id='cNY3z'><dt id='cNY3z'><q id='cNY3z'><span id='cNY3z'><b id='cNY3z'><form id='cNY3z'><ins id='cNY3z'></ins><ul id='cNY3z'></ul><sub id='cNY3z'></sub></form><legend id='cNY3z'></legend><bdo id='cNY3z'><pre id='cNY3z'><center id='cNY3z'></center></pre></bdo></b><th id='cNY3z'></th></span></q></dt></tr></i><div id='cNY3z'><tfoot id='cNY3z'></tfoot><dl id='cNY3z'><fieldset id='cNY3z'></fieldset></dl></div>

                      1. <tfoot id='cNY3z'></tfoot>

                              <tbody id='cNY3z'></tbody>

                            <small id='cNY3z'></small><noframes id='cNY3z'>

                            <legend id='cNY3z'><style id='cNY3z'><dir id='cNY3z'><q id='cNY3z'></q></dir></style></legend>