Disable ui-sref based on a condition

前端 未结 7 734
没有蜡笔的小新
没有蜡笔的小新 2020-12-16 11:22

Can you tell me a way to disable the submit button, which changes to a new state by:

Submit

The butto

7条回答
  •  余生分开走
    2020-12-16 11:42

    My take on the directive provided by @m59 (without introducing an isolated scope):

    .directive('uiSrefIf', function($compile) {
        return {
            link: function($scope, $element, $attrs) {
    
                var uiSrefVal = $attrs.uiSrefVal,
                    uiSrefIf  = $attrs.uiSrefIf;
    
                $element.removeAttr('ui-sref-if');
                $element.removeAttr('ui-sref-val');
    
    
    
                $scope.$watch(
                    function(){
                        return $scope.$eval(uiSrefIf);
                    },
                    function(bool) {
                        if (bool) {
    
                            $element.attr('ui-sref', uiSrefVal);
                        } else {
    
                            $element.removeAttr('ui-sref');
                            $element.removeAttr('href');
                        }
                        $compile($element)($scope);
                    }
                );
            }
        };
    })
    

提交回复
热议问题