【问题标题】:AngularJS Accordion is-open call to functionAngularJS Accordion is-open 函数调用
【发布时间】:2015-11-21 07:49:17
【问题描述】:

如果它是我的任务列表的当前元素,我正在尝试动态打开手风琴元素。这是我的 HTML:

<div ng-controller="taskController">
<uib-accordion close-others="oneAtATime">
            <uib-accordion-group heading="{{task.id}}: {{task.subject}}"  ng-repeat="task in datafromRedmine.issues" class="priority{{task.priority.id}}">
                <div id="midRow">

                    {{task.tracker.name}}-{{task.project.name}}

                </div>
(...)
</uib-accordion-group>

    </uib-accordion>
</div>

谁使用具有此功能的 Angular 控制器:

$scope.isTheCurrent = function (id){
        return(id == $scope.Currentid);
}

我正在尝试在 ng-repeat 旁边添加 is-open="{{isTheCurrent(task.id)}}",但控制台显示

Error: [$parse:syntax] Syntax Error: Token '{' invalid key at column 2 of the expression [{{isTheCurrent(task.id)}}] starting at [{isTheCurrent(task.id)}}].

如何返回一个布尔值,检查 ng-repeat 中的 task.id 是否与我保存在 $scope.currentId 上的相同?

【问题讨论】:

  • 对我之前的回答道歉,我忽略了几件事。第一个问题是不需要{{ .. }} 语法。然而,这无关紧要,因为 is-open 需要一个可分配的值,这意味着您可能必须确定控制器中哪个手风琴处于活动状态并将其作为变量传递

标签: javascript angularjs


【解决方案1】:

ng-repeat 指令实现了一些特殊属性。其中之一是$index。您可以在函数调用中使用它。例如:

<div ng-show="isTheCurrent(datafromRedmine.issues[$index].id)">
     This is current the issue<br>
     {{task}}
</div>

有关$index 特殊属性的更多信息,请阅读AngularJS ng-repeat API Docs

【讨论】:

    猜你喜欢
    • 2014-08-03
    • 2016-12-09
    • 2019-06-30
    • 2011-04-15
    • 2014-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多