【问题标题】:Angular2 cant bind element in angular2-infinite-scrollAngular 无法在 Angular 2-infinite-scroll 中绑定元素
【发布时间】:2017-12-20 06:49:41
【问题描述】:

我是 angular 2 的新手,我所做的是使用 angular 无限滚动并在滚动滚动时加载数据但它提示一些错误无法绑定属性我在下面错误说明:

安装 angular 2-infinite-scroll

import { NgModule, enableProdMode, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpModule } from '@angular/http';
import { FormsModule } from '@angular/forms';
import { Routes } from '@angular/router';

import { AppComponent } from './app/app.component';

/* Feature Modules */
import { DatepickerModule } from 'ng2-bootstrap/ng2-bootstrap';
import { PlanModule } from './plan.module';
import { InfiniteScrollModule } from 'angular2-infinite-scroll';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';


enableProdMode();
@NgModule({
    imports: [
        BrowserModule,
        HttpModule,
        FormsModule,
        DatepickerModule.forRoot(),
        PlanModule,
        InfiniteScrollModule

    ],
    declarations: [],
    bootstrap: [AppComponent],
    schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class AppModule { }
platformBrowserDynamic().bootstrapModule(AppModule);

添加html页面

 <div id="activityList" *ngIf="structure.jobplan" infinite-scroll
            [infiniteScrollDistance]="2"
            [infiniteScrollThrottle]="300"
         (scrolled)="bindActivitiesOnScroll($event)" >

然后我得到了错误:

Uncaught Error: Template parse errors:
Can't bind to 'infiniteScrollDistance' since it isn't a known property of 'div'. ("

    <div id="activityList" *ngIf="structure.jobplan" infinite-scroll
            [ERROR ->][infiniteScrollDistance]="2"
            [infiniteScrollThrottle]="300"
         (scrolled)="bindAct"): ng:///ActivityModule/ActivityListComponent.html@5:12
Can't bind to 'infiniteScrollThrottle' since it isn't a known property of 'div'. ("t" *ngIf="structure.jobplan" infinite-scroll
            [infiniteScrollDistance]="2"
            [ERROR ->][infiniteScrollThrottle]="300"
         (scrolled)="bindActivitiesOnScroll($event)" >

"): ng:///ActivityModule/ActivityListComponent.html@6:12
    at syntaxError (index.ts:26)
    at TemplateParser.parse (index.ts:26)
    at JitCompiler._compileTemplate (index.ts:26)
    at index.ts:26
    at Set.forEach (<anonymous>)
    at JitCompiler._compileComponents (index.ts:26)
    at index.ts:26
    at Object.then (index.ts:26)
    at JitCompiler._compileModuleAndComponents (index.ts:26)
    at JitCompiler.compileModuleAsync (index.ts:26)

我用谷歌搜索但找不到解决方案为什么它不允许绑定属性, 找不到我出错的地方请帮助我

【问题讨论】:

  • 这个库好像被弃用了,你应该升级到新版本github.com/orizens/ngx-infinite-scroll
  • @trungk18 ,我将 angualr2-infinite_scroll 更新为 rgx-infinate-scroll 但问题未解决仍然错误保持不变
  • 这很奇怪,因为您的语法似乎正确。你的组件在哪里?这仍然在 AppModule 中还是在不同的模块中?
  • 它在另一个模块中,而不是在 AppModule 中
  • 非常感谢 trungk18,混淆是模块,我导入 InfiniteScrollModule dif 模块,现在它工作正常

标签: asp.net-mvc angular2-template


【解决方案1】:

我所做的是导入

从 'angular2-infinite-scroll' 导入 { InfiniteScrollModule };

在我的 app.module.ts 中

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-12
    • 1970-01-01
    • 1970-01-01
    • 2015-10-19
    相关资源
    最近更新 更多