ng-if用于Angularjs

时间:2016-12-10 05:14:12

标签: angularjs json

我根据以下内容获得了一个类JSON数据的TreeGrid:

[
{
"DemographicId": 1,
"ParentId": null,
"Name": "United States of America",
"Description": "United States of America",
"Area": 9826675,
  "Area1": 9826675,
"Population": 318212000,
"TimeZone": "UTC -5 to -10",
"وضعیت": "cccxzcxzc",
"Locate": "cccxzcxzc"
}

我有一个指令类angularjs根据:

  module.directive('treeGrid', [
  '$timeout', function ($timeout) {
      return {
          restrict: 'E',
          //templateUrl:'tree-grid-template.html',
          template: "<div><table class=\"table table-bordered table-striped tree-grid\"><thead class=\"text-primary\"><tr><th>{{expandingProperty}}</th><th ng-repeat=\"col in colDefinitions\">{{col.displayName || col.field}}</th></tr></thead><tbody><tr ng-repeat=\"row in tree_rows | filter:{visible:true} track by row.branch.uid\" ng-class=\"'level-' + {{ row.level }} + (row.branch.selected ? ' active':'')\" class=\"tree-grid-row\"><td class=\"text-primary\"><a ng-click=\"user_clicks_branch(row.branch)\"><i ng-class=\"row.tree_icon\" ng-click=\"row.branch.expanded = !row.branch.expanded\" class=\"indented tree-icon\"></i></a><span class=\"indented tree-label\">{{row.branch[expandingProperty]}}</span></td><td  ng-repeat=\"col in colDefinitions\"><input type=text value={{row.branch[col.field]}}></td></tr></tbody><table></div>",
          replace: true,
          scope: {
              treeData: '=',
              colDefs: '=',
              expandOn: '=',
              onSelect: '&',
              initialSelection: '@',
              treeControl: '='
          },
          link: function (scope, element, attrs) {
              var error, expandingProperty, expand_all_parents, expand_level, for_all_ancestors, for_each_branch, get_parent, n, on_treeData_change, select_branch, selected_branch, tree;
              error = function (s) {
                  console.log('ERROR:' + s);
                  debugger;
                  return void 0;
              }

<input type=text value={{row.branch[col.field]}}>中我希望当字段我的数据json Area=9826675将输入放入<td ng-repeat=\"col in colDefinitions\"><input type=text value={{row.branch[col.field]}}></td>时,如果区域!= 9826675放置<td ng-repeat=\"col in colDefinitions\">{{row.branch[col.field]}}></td>

1 个答案:

答案 0 :(得分:0)

很难在一行读取所有内容,但尝试这样的事情:

<div data-ng-repeat="col in colDefinitions">
  <div data-ng-if="col.Area===9826675">
     version A
  </div>
  <div data-ng-if="col.Area!==9826675">
     version B
  </div>
</div>