Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 更改angularJS指令的值后按钮未启用_Javascript_Jquery_Jquery Ui_Angularjs - Fatal编程技术网

Javascript 更改angularJS指令的值后按钮未启用

Javascript 更改angularJS指令的值后按钮未启用,javascript,jquery,jquery-ui,angularjs,Javascript,Jquery,Jquery Ui,Angularjs,基本上,我得到了一个带有按钮和可选列表的AngularJS指令(jQueryUI) 使用ng disabled=“disabledButton”禁用该按钮 disabledButton是控制器中的一个变量$scope.disabledButton=true 现在,在指令中,单击列表中的一个元素后,我想将disabledButton设置为false,这样按钮就会被激活 以下是我的HTML代码: 将$scope.$watch替换为$scope.$apply您的代码不做任何操作,因为$scope.$

基本上,我得到了一个带有按钮和可选列表的AngularJS指令(jQueryUI)

使用ng disabled=“disabledButton”禁用该按钮

disabledButton是控制器中的一个变量
$scope.disabledButton=true

现在,在指令中,单击列表中的一个元素后,我想将disabledButton设置为false,这样按钮就会被激活

以下是我的HTML代码:


将$scope.$watch替换为$scope.$apply您的代码不做任何操作,因为$scope.$watch只监视作用域中的值以进行更改。我在代码中添加了另一个内容,我假装这样做,将所选对象的数组返回给控制器。。。我试图在指令中使用内部控制器,但我无法从父控制器看到它,也许我应该添加$broadcast/$emit?这是个好主意,对吧?如果可以的话,创作小提琴。可能您可以使用ng click='enableButton();'在每个li中,以及在控制器scope.enableButton=function(){scope.disableButton=false;}中,您可以通过这种方式删除链接函数mmm不,我不能:(难道没有办法从指令中执行吗?:S
<div class="modal-wrapper">
    <div panels test-data="testData" disable-button='disableButton'></div>

    <div class="bottom-buttons">
        <button ng-disabled="disableButton" class="btn btn-primary btn-wizard" ng-click="alertSelected()">NEXT</button>
    </div>
</div>
portfolioApp.directive('panels', function($timeout) {
    return {
        restrict: 'A',
        replace: true,
        templateUrl: 'templates/paneltemplate.htm',
        scope: {
            testData: "=",
            disableButton: "@"
            //selectedList: "@"
        },
        controller: function($scope) {
            $scope.selectedList = [];

            $scope.clearList = function() {
                $scope.selectedList.length = 0;
            }
        },
        link: function($scope, element, attrs, panelsController) {
            $timeout(function() {
                if(!$scope.$$phase) {
                    $('#selectable').selectable( {
                        filter: "li",
                        selected: function(event, elem) {

                            // this will return the first of the selecteds
                            var selecteds = $('#selectable').find('.ui-selected').children().eq(0).children().text();

                            $scope.selectedList.push(selecteds);
                            console.log($scope.selectedList);

                            $scope.$apply(function() {
                                $scope.disableButton = false;
                            });

                            console.log('look im being selected!')
                        },
                        unselected: function(event, ui) {
                            $scope.clearList();
                        }
                    }); 
                    $scope.$apply();
                }
            },0);           
        }
    }
})
link: function(scope, element, attrs) {
        $timeout(function() {
            if(!scope.$$phase) {
                $('#selectable').selectable( {
                    filter: "li",
                    selected: function(event, elem) {

                        scope.$apply(function() {
                            scope.disableButton = false;
                        });
                        console.log('look im being selected!')
                    }
                }); 
            }
        },0);           
    }