如何传递可能作为指令参数更改的范围变量

时间:2016-11-23 06:44:14

标签: angularjs angularjs-directive angular-directive

您好我有以下指示:

    app.directive('multiselectTableFilter', ['dependency1',
        function (dependency1) {
        return {
            restrict: 'E',
            scope: {
                model: '=',
                options: '=',
            },
            template:
                    "<div class='btn-group' data-ng-class='{open: open}'>" +
                        "<button class='btn btn-link btn-xs dropdown-toggle' data-ng-click='openDropdown()' ng-class=\"model.length !== options.length ? 'filterEdited' : ''\"><i class='fa fa-filter'></i></button>" +
                        "<ul class='dropdown-menu' aria-labelledby='dropdownMenu'>" +
                            "<li data-ng-repeat='option in options'><a data-ng-click='toggleSelectItem(option)'><span data-ng-class='getClassName(option)' aria-hidden='true'></span> {{option}}</a></li>" +
                        "</ul>" +
                    "</div>",

            controller: function ($scope) {
                $scope.filteredElement = {};
                $scope.openDropdown = function () {
                    $scope.open = !$scope.open;
                };
                console.log($scope.model); console.log($scope.options);
  }]);
 })(app);

这就是我称之为指令的方式:

<a href=""><multiselect-table-filter model="selectedUserIds.bugSeverity" options="options2"></multiselect-table-filter> </a>

在Controller中,我分配selectedUserIds和options2的值。

$scope.getFilteredData = function(list, filters){ 
        $scope.filteredData = $filter('inArray')($scope.p0Bugs, $scope.selectedUserIds.bugStatus, "bugStatus");
        $scope.filteredData = $filter('inArray')($scope.filteredData, $scope.selectedUserIds.bugSeverity, "bugSeverity");
        $scope.severity = _.uniq(_.map($scope.filteredData, "bugSeverity"));
        $scope.options2 = $scope.severity; // **when I assign options2 to this value, it throws error. (digest cycle error)**
        console.log($scope.filteredData);
        console.log($scope.severity)
        return $scope.filteredData;
};

任何人都可以帮我解决这个问题。我如何将更新的$ scope.options2值传递给指令。如果您需要更多信息,请与我们联系。

0 个答案:

没有答案