Hướng dẫn display array in html angular - mảng hiển thị trong góc html

Tôi nhận được tất cả dữ liệu JSON từ WS như thế này:

{
  "StatusCode":0,
  "StatusMessage":"OK",
  "StatusDescription":   
   [
      {"homeboxpackage_id":"1",
        "active":0,
        "homebox_id":"11",
        "serial_number":"serialn1",
        "user_id":"31", 
        "sensors": { 
              "0":{
                    "sensor_serial":"sensorserial1",
                    "sensors_id":"11E805BA6732C3DB"
              }, 
              "1":{
                    "sensor_serial":"sensorserial2", 
                    "sensors_id":"11E805BA6F1E6CE9"
              }, 
              "2":{
                    "sensor_serial":"sensorserial3", 
                    "sensors_id":"11E805BA7716C775"
              }
        }
    }
  ]

Trong mã HTML, tôi muốn hiển thị các cảm biến dữ liệu trong danh sách, nhưng DOS không hiển thị. Mã HTML của tôi:

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}

Homeboxsp nằm trong thành phần.ts

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];

hình ảnh

[1]: //i.stack.imgur.com/qxrtr.png

Cảm ơn bạn

Cho một mảng & nhiệm vụ là in mảng đã cho ở định dạng bảng bằng cách sử dụng angularjs.

Trong JavaScript, dữ liệu có thể được lưu trữ dưới dạng mảng. Mỗi mục mảng có lập chỉ mục duy nhất, bắt đầu từ 0. Nhưng điều gì sẽ xảy ra nếu nhà phát triển muốn hiển thị tất cả các mục trong mảng, trên trang web. Một cách có thể là chạy một vòng lặp, bắt đầu từ 0 đến giá trị của [mảng.length [] - 1]. Tuy nhiên, điều này là không khả thi trong khi xử lý dữ liệu JSON, trong đó có thể tồn tại một mảng khác bên trong một mảng đã tồn tại. & NBSP;

Giải pháp tốt nhất có thể cho việc này đã được cung cấp bởi angularjs.an mảng có thể được in ở định dạng bảng bằng cách sử dụng chỉ thị ’ng-lặp lại của angularjs. Ng-lặp lại giúp lặp lại các mục trong phần tử thu thập. Chỉ thị này rất hữu ích trong khi xử lý một bộ sưu tập các đối tượng. & NBSP;An array can be printed in tabular format using the ‘ng-repeat’ directive of AngularJS. ‘ng-repeat’ helps in looping through the items in the collection element. This directive is very helpful while dealing with a collection of objects. 

Ví dụ 1: Ví dụ này minh họa việc kết xuất mảng ở dạng bảng bằng cách sử dụng Chỉ thị lặp lại trong AngularJS. This example illustrates the rendering of the array in the tabular form using the ng-repeat directive in AngularJS.

HTML

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
1

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
1 { this.homeboxsp = homeboxsp; // in console display all my array in array } ]; 2>

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
4
 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
5

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
6
 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
7

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
6
 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
9

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
4
{{x}}
1

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
4
{{x}}
3

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
4
{{x}}
5

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
6
{{x}}
7

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
4
{{x}}
1

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
1
  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
7
 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
2>

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
7head>

{ this.homeboxsp = homeboxsp; // in console display all my array in array } ]; 4

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
7

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
4

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
6

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
6

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
6

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
6

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
6

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
4
  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
7head0>

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
1
  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
7>9>

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
78>

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
1
  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
82

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
1
  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
84

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
4
  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
86

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
6
  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
88

head2

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
90

head2

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
92

head2

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
94

head2

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
96

head2

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
98

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
6
 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
00

head2

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
02

head2

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
04

head2

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
06

head2

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
08

head2

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
98

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
6
 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
00

head2

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
14

head2

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
16

head2

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
18

head2

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
20

head2

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
98

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
6
 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
00

head2

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
26

head2

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
28

head2

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
30

head2

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
32

head2

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
34

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
6
 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
00

head2

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
38

head2

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
40

head2

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
42

head2

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
44

head2

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
34

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
6
{{x}}
1

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
6
 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
50

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
4
 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
52

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
7
  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
3>

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
7html>

Giải thích: ‘ng-app‘ và bộ điều khiển ‘ng‘ của ứng dụng này đã được đặt tên tương ứng ‘myApp, và‘ listControll. Trong, một mảng có tên ‘itemDetails đã được tạo và lưu trữ trong biến phạm vi. Mảng chứa một danh sách các người chiến thắng top 5 Grand Slam trong quần vợt nam. & NBSP; The ng-app and the ng-controller of this application have been named ‘myApp’, and ‘ListController’ respectively. In the , an array named ‘itemsDetails’ has been created and stored in the scope variable. The array contains a list of the ‘Top 5 Grand Slam winners in Men’s Tennis. 

Output:

Mục tiêu chính là in dữ liệu này theo một mảng ở định dạng bảng. Bước đầu tiên là tạo một bảng bằng cách sử dụng các thẻ ‘bảng,‘, ‘tr‘, ‘TD‘ thẻ. Các tiêu đề bảng được đặt. Dịch vụ lặp lại của AngularJS trích xuất nhiều bản ghi từ mảng. & NBSP;table, thead, tr, td tags. The table headings are set. The ng-repeat service of AngularJS extracts multiple records from the array. 

Cú pháp của ‘ng-lặp lại:

{{x}}

Ví dụ 2: Trong ví dụ dưới đây, cú pháp đã được sửa đổi là ng-repeat = mục trong các mục. Do đó, mỗi mục của ‘itemdetails, sẽ được xác định là một’ mặt hàng. Ký hiệu chấm JavaScript sẽ được sử dụng để truy cập thông tin bên trong mảng. Ví dụ: để truy cập thông tin được lưu trữ trong ‘Tên, ký hiệu dấu chấm‘ itemsDetails.name, sẽ được sử dụng. Bước tiếp theo là viết ký hiệu chấm đó bên trong dấu ngoặc đôi {{}}, ví dụ; {{itemsDetails.name}}. Angularjs sau đó giải quyết biểu thức này và trả về kết quả mong muốn. ‘NG-Repeat, sẽ chạy quy trình này trong một vòng lặp cho đến khi tất cả các mục mảng được chọn và trả về ở định dạng bảng. & NBSP; In the below example, the syntax has been modified as ng-repeat=”item in itemsDetails. Therefore, each item of the ‘itemsDetails’ will be identified as an ‘item’. The JavaScript dot notation will be used to access information inside the array. For example, to access the information that is stored in ‘name’, the dot notation ‘itemsDetails.name’ will be used. The next step is to write that dot notation inside double brackets {{}}, for example; {{itemsDetails.name}}. AngularJS then resolves this expression and returns the desired result. The ‘ng-repeat’ will run this process in a loop until all the array items are selected and returned in the tabular format. 

HTML

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
1

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
1 { this.homeboxsp = homeboxsp; // in console display all my array in array } ]; 222

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
4
 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
5

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
6
 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
7

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
6
 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
9

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
4
{{x}}
1

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
4
{{x}}
3

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
4
{{x}}
5

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
6
{{x}}
7

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
4
{{x}}
1

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
1
  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
7
 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
2>

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
7head>

{ this.homeboxsp = homeboxsp; // in console display all my array in array } ]; 6 { this.homeboxsp = homeboxsp; // in console display all my array in array } ]; 4

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
7head0>

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
1
  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
7>9>

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
78>

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
1
  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
82

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
103

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
4
  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
88

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
607

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
609

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
4
 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
00

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
613

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
615

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
4
 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
00

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
619

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
609

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
4
 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
00

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
625

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
615

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
4
 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
00

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
631

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
615

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
4
{{x}}
1

 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
4
 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
50

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
1
 this.ws.homeboxPGetAll[].subscribe[
      homeboxsp => {
        this.homeboxsp = homeboxsp; // in console display all my array in array
           }
    ];
52

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
7
  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
3>

  
        
          Serial Number
        
        
          Sensor Serial
        
      
  • {{item.sensors}}
{{item.serial_number}} {{item.active}}
7html>

Giải thích: Ví dụ này rất giống với ví dụ trước. Trong trường hợp này, chúng tôi đã tạo một mảng và đặt tên nó là ‘itemDetails. Chúng tôi sẽ lưu trữ mảng này trong đối tượng phạm vi. Dịch vụ ‘ng-repeat, sẽ lặp lại thông qua mảng, nhận một mục tại một thời điểm từ mảng và sau đó hiển thị nó trên trang web ở định dạng bảng. This example is very much similar to the previous example. In this case, we created an array and named it ‘itemsDetails’. We will store this array in the scope object. The ‘ng-repeat’ service will iterate through the array, get one item at a time from the array, and then display it on the webpage in the tabular format.

Output:  


Làm thế nào để in mảng trong html Angular?

Một mảng có thể được in ở định dạng bảng bằng cách sử dụng chỉ thị 'ng-repeat' của angularjs.'NG-Repeat' giúp lặp qua các mục trong phần tử thu thập.Chỉ thị này rất hữu ích trong khi xử lý một bộ sưu tập các đối tượng.using the 'ng-repeat' directive of AngularJS. 'ng-repeat' helps in looping through the items in the collection element. This directive is very helpful while dealing with a collection of objects.

Làm thế nào để bạn hiển thị dữ liệu trong một mảng trong HTML?

foreach [phần tử => {document.getEuityById ['result']. InsideHtml += `$ {Element}`; // ở đây kết quả là id của div có trong DOM}];};Mã này đưa ra giả định rằng div mà chúng tôi muốn hiển thị các phần tử của mảng có ID 'kết quả'. getElementById['result']. innerHTML += `
${element}

`; // here result is the id of the div present in the DOM }]; };
This code makes the assumption that the div in which we want to display the elements of array has an id 'result'.

Bài Viết Liên Quan

Chủ Đề