ng-repeat和ng-如果不起作用

时间:2017-04-04 17:45:13

标签: javascript html angularjs json

我想做以下事情:

  1. 根据某些条件显示页面上的所有html元素, 我的理解是我可以使用ng-if。
  2. 如果employeeList为空,那么我是否需要创建内部元素的另一个副本以确保它显示在页面上
  3. ng-if打印div和spans,其中只有一个应该打印,我的html就是这个
  4. HTML:

     <div class="container" ng-controller="profileController" ng-init="loadProfilesData()">
        <div ng-repeat="p in profileData">
            <div>{{p.company}}</div>
            <div>{{p.department}}</div>
    
            <div ng-repeat="emp in p.employeeList"></div>
    
                <div ng-if="emp.Tag== 'Devo100'" gauge-chart class="gauge" id="Devo100-{{p.Id}}" value=p.Value*100></div>
                <div ng-if="emp.Tag!= 'Devo100'" gauge-chart class="gauge" id="Devo100-{{p.Id}}" value=0></div>
    
                <span ng-if="emp.Tag== 'Devo102'">
                   {{ p.Value | date: "hh:mm:ss" }}
                </span>
                <span ng-if="emp.Tag== 'Devo102'">
                   0
                </span>
    
            </div>
        </div>                
    </div>
    

    我的json正在关注

    profileData: [  
                      {
                       ID: "1",
                       metricStatList: [{"Value":0.003,"Stat":{"parameter":0,"Name":"test0","Tag":"Devo100"}},
                                     {"Value":0.004,"Stat":{"parameter":0,"Name":"test1","Tag":"Devo101"}},
                                     {"Value":0.005,"Stat":{"parameter":0,"Name":"test2","Tag":"Devo102"}}],                  
                       comapny: "MSDFT",
                       department: "Sales"
                      },
                      {
                       ID: "2",
                       metricStatList: null,                  
                       comapny: "MSDFT",
                       department: "HR"
                      },
                      {
                       ID: "3",
                       metricStatList: [{"Value":0.003,"Stat":{"parameter":0,"Name":"test0","Tag":"Devo100"}},
                                     {"Value":0.004,"Stat":{"parameter":0,"Name":"test1","Tag":"Devo101"}}],                  
                       comapny: "MSDFT",
                       department: "Development"
                      },
                      {
                       ID: "4",
                       metricStatList: [{"Value":0.1,"Stat":{"parameter":0,"Name":"test2","Tag":"Devo102"}},
                                     {"Value":0.25,"Stat":{"parameter":0,"Name":"test1","Tag":"Devo101"}}],                  
                       comapny: "MSDFT",
                       department: "Finance"
                      },
                      {
                       ID: "5",
                       metricStatList: [{"Value":0.233,"Stat":{"parameter":0,"Name":"test0","Tag":"Devo100"}}],                  
                       comapny: "MSDFT",
                       department: "Accounts"
                      }
                    ]
    

0 个答案:

没有答案