AngularJs seperate array and string in HTML template

后端 未结 3 1879
北荒
北荒 2021-01-28 00:33

I have a little problem with creating a dynamic HTML template. To display some data in a table, I have to separate between an ordinary String and an Array. First things first: T

相关标签:
3条回答
  • 2021-01-28 00:49

    Do Something Like this.

    <tr ng-repeat="person in persons">
       <td ng-repeat="attr in query.attribs">
         <span ng-show="isArray(person[attr.id])">
           {{person[attr.id].toString()}}  
         </span>
         <span ng-show="!isArray(person[attr.id])">
           {{person[attr.id]}}
         </span>
       </td>
    </tr>  
    
    0 讨论(0)
  • 2021-01-28 00:52

    You have to do some script and html changes if the value is an array like this Updated fiddle here : jsfiddle.net/Lt024p9h/7/

    0 讨论(0)
  • 2021-01-28 00:59

    you can isArray but not directly inside ng-show.

    you can use it like this.

     $scope.isArray = angular.isArray;
    

    so this way,

     <tr ng-repeat="person in persons">
       <td ng-repeat="attr in query.attribs">
         <span ng-show="isArray(person[attr.id])">
           <span ng-repeat="p in person[attr.id]">
              {{p}}
           </span>
         </span>
         <span ng-show="!isArray(person[attr.id])">
           {{person[attr.id]}}
         </span>
       </td>
    </tr>
    

    Here is your updated Fiddle

    0 讨论(0)
提交回复
热议问题