简体   繁体   English

AngularJS手风琴是对函数的开放调用

[英]AngularJS Accordion is-open call to function

I'm trying to dinamically open a element of the accordion if it's the current element of my task list. 如果它是我任务列表中的当前元素,我试图以动态方式打开它的一个元素。 This is my HTML: 这是我的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>

Who uses an Angular Controller with this function: 谁将Angular Controller与该功能配合使用:

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

I'm trying to add next to ng-repeat a is-open="{{isTheCurrent(task.id)}}", but console says 我正在尝试在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)}}].

How can I return a boolean checking if the task.id from the ng-repeat is the same as the one I've saved on $scope.currentId? 如何返回布尔检查ng-repeat中的task.id是否与我保存在$ scope.currentId上的布尔值相同?

The ng-repeat directive implements some special properties. ng-repeat指令实现了一些特殊的属性。 One of them is $index . 其中之一是$index You can use that in your function call. 您可以在函数调用中使用它。 For instance: 例如:

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

For more information on the $index special property, read the AngularJS ng-repeat API Docs 有关$index特殊属性的更多信息,请阅读AngularJS ng-repeat API文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM