如何评估AngularJS中表达式内的表达式

时间:2015-06-19 22:38:53

标签: angularjs

我正在尝试使用angularJS评估表达式内的表达式。请告诉我怎么做?

问题:

我有两个对象部门和设施,我想用手风琴展示部门和设施。所以,我能够传递部门对象和设施对象。现在出现了问题。由于department对象具有属性department_name,而facility具有facility_name.I传递了department_name和 facility_name用于标记指令中的属性并尝试使用手风琴html,如{{item。{{label}}}}。我不认为这是正确的。但是,请让我知道我该怎么做。

提前致谢

在HTML中:

 <accordion-directive object="department" label="department_name">
 </accordion-directive>
 <accordion-directive object="facility" label="facility_name">
</accordion-directive>

在Accordion HTML中

 <accordion-group ng-repeat="item in object>
 <accordion-heading>
{{item.{{label}}}} // For departments it should be  department[0].department_name
                 // For Facility it should be facility[0].facility_name

 </accordion-heading>
</accordion-group>

JSON文件:

    {
   "department": [
                   {
                     "department_name": "department 1", 
                   },
                  {
                   "department_name": "department 2",
                  } 
                 ]
        }

       {
    "facility": [
                   {
                    "facility_name": "Facility 1"
                   },
                   {
                    "facility_name": "Facility 2"
                   }
                ]
}

指令:

          angular.module("app").directive('accordDirective', function () {
           return {
           restrict: 'E',
             scope: {
               object: '=',
               label:'@'
              },
             templateUrl: 'accordian.html',    
        }

1 个答案:

答案 0 :(得分:4)

使用方括号:

{{item[label]}}