简体   繁体   English

无法绑定到“ngForOf”,因为它不是“div”的已知属性。 - App.module.ts 已经有正确的引用

[英]Can't bind to 'ngForOf' since it isn't a known property of 'div'. - App.module.ts already has right references

My App.module.ts looks like this:我的 App.module.ts 看起来像这样:

    import { BrowserModule } from '@angular/platform-browser';
      imports: [
        BrowserModule,
        //import HttpclientModule after BrowserModule
        HttpClientModule,
        AppRoutingModule,
        BrowserAnimationsModule,
        DefaultModule,
    
  ],

I use in another component -> test.component.html我在另一个组件中使用 -> test.component.html

<div *ngFor="let list of JsonData">

{{title}}

</div>

But I don't understand the error message?但是我不明白错误信息?

the JsonData structure looks like that: JsonData 结构如下所示:

Downloaded blob content {
"name": "test_sensor",
"timestamp": 1597925753,
"value": 12
}

The json-data.service.ts, where I retrieve the data from the Blobstorage: json-data.service.ts,我从 Blobstorage 检索数据的地方:

import { Injectable } from '@angular/core';
import { environment } from '../../environments/environment';
import { JsonData } from '../models/jsondata';

import {
  BlobServiceClient,
  BlobDownloadResponseModel
} from "@azure/storage-blob";




@Injectable({
  providedIn: 'root'
})

    export class JsonDataService {
      private account = environment.ACCOUNT_NAME;
      
      private sas = environment.SAS;
      private blobServiceClient
    
      constructor() { this.blobServiceClient = new BlobServiceClient( `https://${this.account}.blob.core.windows.net${this.sas}`)}
    
    
      getData(): Promise<JsonData[]> {
    
        /*const blobServiceClient = new BlobServiceClient(
    
          `https://${this.account}.blob.core.windows.net${this.sas}`,
        );*/
    
    
        return new Promise(resolve => {
            
        
    
          const containerName = "container1";
          const containerClient = this.blobServiceClient.getContainerClient(containerName);
    
    
    
    
          //list blobs
          let i = 1;
          
          async function main() {
            i = 1;
            for await (const blob of containerClient.listBlobsFlat()) {
    
              console.log(`Blob ${i++}: ${blob.name}`);
              const blockBlobClient = containerClient.getBlockBlobClient(blob.name);
    

    
              const downloadBlockBlobResponse =  await blockBlobClient.download(0);
              const download = await blobToString(await downloadBlockBlobResponse.blobBody)
         
              console.log("Downloaded blob content",
               download
              );
    
            }
    
          }
    
          //BROWSER ONLY A HELPER METHOD USED TO CONVERT A BROWSER BLOB INTO STRING
          async function blobToString(blob: Blob): Promise<string> {
            const fileReader = new FileReader();
            return new Promise((resolve, reject) => {
             fileReader.onloadend = (ev: any ) => {
               resolve(ev.target!.result);
             };
             fileReader.onerror = reject;
             fileReader.readAsText(blob);
            });
          }
    
          main().catch((err) => {
            console.error("Error running sample:", err.message);
          })
    
        })
    
      }
    
    }

then in the test.component.ts file I want to display the json structure of the downloaded blob file.然后在 test.component.ts 文件中,我想显示下载的 blob 文件的 json 结构。

import { Component, OnInit, Input } from '@angular/core';
import { JsonDataService } from 'src/app/services/json-data.service';
import { JsonData } from 'src/app/models/jsondata';



@Component({
  selector: 'app-posts2',
  templateUrl: './posts2.component.html',
  styleUrls: ['./posts2.component.scss'],
  providers: [JsonDataService]
})



export class Posts2Component implements OnInit {
  @Input() title: string;
  jsondatas: Array<JsonData> = [];
  jsondata: JsonData;
  name: String;
  timestamp: string;
  value: number;


  

  constructor(private jsonService: JsonDataService) {
  
  }

  ngOnInit(): void {
    this.jsonService.getData()
      .then(results => this.jsondatas = results);

    console.log(this.jsonService) **somehow this only shows the credentials (ACCOUNT, SAS) and not get back the jsondata**

  }



}

Make sure you import CommonModule to use directive *ngFor.确保导入 CommonModule 以使用指令 *ngFor。 It is part of CommonModule.它是 CommonModule 的一部分。 Please add the common module to the module where TestComponent is declared.请将公共模块添加到声明 TestComponent 的模块中。

import { CommonModule} from '@angular/common';
  imports: [
CommonModule
],

Please find more info here: https://angular.io/guide/frequent-ngmodules请在此处找到更多信息: https://angular.io/guide/frequent-ngmodules

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法绑定到“ngForOf”,因为它不是“div”的已知属性。 ngFor 不在浏览器中显示任何内容 - Can't bind to 'ngForOf' since it isn't a known property of 'div'. ngFor not displaying anything in the browser 无法绑定到“ngForOf”,因为它不是 ngFor Angular 中“li”的已知属性 - Can't bind to 'ngForOf' since it isn't a known property of 'li' in ngFor Angular 无法绑定到“ useStickyClasses”,因为它不是“ div”的已知属性 - Can't bind to 'useStickyClasses' since it isn't a known property of 'div' 在控制台中出现错误无法绑定到“ngif”,因为它不是 angular 应用程序中“div”的已知属性 - Getting error in console Can't bind to 'ngif' since it isn't a known property of 'div' in angular app 无法绑定到“数据集”,因为它不是“画布”的已知属性 - Can't bind to 'datasets' since it isn't a known property of 'canvas' 无法绑定,因为它不是选择器组件的已知属性 - Can't bind to since it isn't a known property of selector component 无法绑定到“”,因为它不是“ angular 2”的已知属性 - can't bind to '' since it isn't a known property of '' angular 2 无法绑定到“控件”,因为它不是(myComponent)的已知属性 - Can't bind to 'control' since it isn't a known property of (myComponent) Angular 7:无法绑定到“元素”,因为它不是 - Angular 7 : Can't bind to 'element' since it isn't a known property of 无法绑定到“matMenuTrigger”,因为它不是“a”的已知属性 - Can't bind to 'matMenuTrigger' since it isn't a known property of 'a'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM