简体   繁体   English

无法绑定到“ngForOf”,因为它不是 ngFor Angular 中“li”的已知属性

[英]Can't bind to 'ngForOf' since it isn't a known property of 'li' in ngFor Angular

I saw another question about the same problem, but I don't know why I get this error.我看到另一个关于同一问题的问题,但我不知道为什么会出现此错误。 The odd thing here is that I did another component that returns a array and works fine, now I've created this new one but it doesn't work.奇怪的是,我做了另一个组件,它返回一个数组并且工作正常,现在我创建了这个新组件,但它不起作用。

Can't bind to 'ngForOf' since it isn't a known property of 'li'无法绑定到“ngForOf”,因为它不是“li”的已知属性

this is my component SubscriptionCustumerComponent:这是我的组件订阅客户组件:

    public subscriptions:Subscription[];

constructor(private subscriptionService:CustumerSubscriptionService){} 

ngOnInit(): void {

        this.subscriptionService.getsubscriptionbyID(this.userid)
        .subscribe(res=>this.subscriptions=res,
            error=> this.errorMessage);
    
}

the page:这页纸:

    <ul  class="nav">
    <li *ngFor="let data of subscriptions" >
        <div class="card">
             <img src="{{data.image}}" style="width:100%;height:250px;">
            <h1>{{data.name}}</h1>
          </div>
    </li>
</ul> 

the SubscriptionModule:订阅模块:

import { CommonModule } from "@angular/common";
import { NgModule } from "@angular/core";
import { CustumerSubscriptionService } from "./service/subscription.service";
import { CustumerSubscriptionAppComponent } from "./subscription.app.component";
import { CustumerSubscriptioRoutingModule } from "./subscription.route";

@NgModule({

    declarations:[
        CustumerSubscriptionAppComponent
    ],
    imports:[
        CommonModule,
        CustumerSubscriptioRoutingModule
        
    ],
    providers:[
        CustumerSubscriptionService
    ]
})

export class CustumerSubscriptionModule{}

and the main Module AppModule:和主模块 AppModule:

@NgModule({
  declarations: [
    AppComponent

  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    BrowserAnimationsModule,
    NavegacaoModule,
    NgbModule,
    ToastrModule.forRoot(),
    HttpClientModule
  ],
  providers: [httpInterceptorProviders],
  bootstrap: [AppComponent]
})
export class AppModule { }

double check what your service is returning.仔细检查您的服务返回的内容。 Most likely this:最有可能的是:

this.subscriptions=res

Is not an array.不是数组。 And the most likely explanation for this is that you are returning a single record based on this.userid, instead of an array.对此最可能的解释是您返回的是基于 this.userid 的单个记录,而不是数组。

try to console.log(this.subscriptions) to see what it is.尝试console.log(this.subscriptions)看看它是什么。 If it's not an array, you will get that error.如果它不是数组,您将收到该错误。

You tell your component is called SubscriptionCustumerComponent , however it is not declared in the SubscriptionModule .你告诉你的组件叫做SubscriptionCustumerComponent ,但是它没有在SubscriptionModule中声明。 Instead, we have CustumerSubscriptionAppComponent .相反,我们有CustumerSubscriptionAppComponent This could be an issue because all other things (including browser module and common module) seem to be correct.这可能是一个问题,因为所有其他内容(包括浏览器模块和公共模块)似乎都是正确的。

暂无
暂无

声明:本站的技术帖子网页,遵循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 Angular 5错误:由于它不是&#39;li&#39;的已知属性,因此无法绑定到&#39;ngForFor&#39; - Angular 5 Error:Can't bind to 'ngForFor' since it isn't a known property of 'li' 我的问题是关于“ ngFor”不是已知的“ li”属性,因此无法绑定到ngFor,为什么会出现此错误? - my question is about Can't bind to 'ngFor' since it isn't a known property of 'li' , Why am getting this error? 无法绑定到“”,因为它不是“ angular 2”的已知属性 - can't bind to '' since it isn't a known property of '' angular 2 Angular 7:无法绑定到“元素”,因为它不是 - Angular 7 : Can't bind to 'element' since it isn't a known property of 无法绑定到“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 无法绑定到“数据集”,因为它不是“画布”的已知属性 - 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 无法绑定到“appIfRoles”,因为它不是“p”的已知属性 - Can't bind to 'appIfRoles' since it isn't a known property of 'p' 无法绑定到“ chartType”,因为它不是“ canvas”的已知属性 - Can't bind to 'chartType' since it isn't a known property of 'canvas'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM