嗨,我已经在 angular 5 中尝试过这个库,但似乎无法让它工作。 我有一个像这样的组件模板
<a class="card clickable" [routerLink]="[product.id]">
<div class="card-img">
<img [lazyLoad]="product.logoUrl">
</div>
<div class="card-block">
<span class="card-media-title">{{product.name}}</span>
<div class="product-version">{{product.version}}</div>
<div class="product-release-date">{{product.releaseDate}}</div>
</div>
</a>
和一个像这样的组件
import {Component, Input} from '@angular/core';
import {Product} from '../products.state';
@Component({
selector: 'app-product-card',
templateUrl: './product-card.component.html',
styleUrls: ['./product-card.component.scss']
})
export class ProductCardComponent {
@Input() product: Product;
constructor() {
}
}
还有我的模块
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {LazyLoadImageModule} from 'ng-lazyload-image';
import {ProductsComponent} from './products.component';
import {ProductsEpic} from './products.epic';
import {ProductsListComponent} from './products-list/products-list.component';
import {ProductCardComponent} from './product-card/product-card.component';
import {ProductsService} from './products.service';
import {ProductsActions} from './products.actions';
import {ProductsEmptyComponent} from './products-empty/products-empty.component';
import {CoreModule} from '../core/core.module';
import {BannerComponent} from './banner/banner.component';
import {RouterModule} from '@angular/router';
@NgModule({
imports: [
CommonModule,
RouterModule,
CoreModule,
LazyLoadImageModule
],
declarations: [
ProductsComponent,
ProductsListComponent,
ProductCardComponent,
ProductsEmptyComponent,
BannerComponent
],
providers: [
ProductsService,
ProductsEpic,
ProductsActions
]
})
export class ProductsModule {
}
图像根本就不会出现。 我也在控制台中收到此警告消息
不知道我做错了什么。 任何帮助表示赞赏
嗨@el-davo,
谢谢你的报告。 您是否使用任何服务器渲染? 或者预编译你的应用程序? 或者你是在开发模式下运行应用程序?
你好。 不,我不是在做服务器端渲染。 是的,目前使用 angular-cli 处于开发模式
你使用的是什么浏览器?
我刚刚使用 cli(Angular 5)创建了一个新的 angular 应用程序,但无法重现这一点。 我做了以下更改:
diff --git a/src/app/app.component.html b/src/app/app.component.html
index 46d517b..215f0c9 100644
--- a/src/app/app.component.html
+++ b/src/app/app.component.html
@@ -6,15 +6,21 @@
<img width="300" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==">
</div>
<h2>Here are some links to help you start: </h2>
+<img [defaultImage]="defaultImage" [lazyLoad]="image">
<ul>
<li>
<h2><a target="_blank" rel="noopener" href="https://angular.io/tutorial">Tour of Heroes</a></h2>
diff --git a/src/app/app.component.ts b/src/app/app.component.ts
index 7b0f672..cf8cead 100644
--- a/src/app/app.component.ts
+++ b/src/app/app.component.ts
@@ -7,4 +7,6 @@ import { Component } from '@angular/core';
})
export class AppComponent {
title = 'app';
+ defaultImage = 'https://www.placecage.com/1000/1000';
+ image = 'https://images.unsplash.com/photo-1443890923422-7819ed4101c0?fm=jpg';
}
diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index 926975a..7fb6d9d 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -1,18 +1,13 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
+import { LazyLoadImageModule } from 'ng-lazyload-image';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
+ LazyLoadImageModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
我还创建了一个 plnkr (https://embed.plnkr.co/rr046QU9YYWALdX7Xzf6/),但无法重现该错误。
你认为你可以创建一个小的 git repo 或 plnkr 来重现错误吗?
我很抱歉。 我仔细查看了我的问题,结果发现我有这段 css 似乎禁用了浏览器中的所有滚动事件
html, body {
overflow-x: hidden;
}
为了解决这个问题,我像这样添加了这个自定义滚动事件
import {Component, Input} from '@angular/core';
import {Product} from '../products.state';
import {Observable} from 'rxjs/Observable';
@Component({
selector: 'app-product-card',
templateUrl: './product-card.component.html',
styleUrls: ['./product-card.component.scss']
})
export class ProductCardComponent {
@Input() product: Product;
scrollObservable = Observable.fromEvent(document.body, 'scroll');
constructor() {
}
}
在我的模板中
<a class="card clickable" [routerLink]="[product.id]">
<div class="card-img">
<img [lazyLoad]="product.logoUrl" [scrollObservable]="scrollObservable">
</div>
<div class="card-block">
<span class="card-media-title">{{product.name}}</span>
<div class="product-version">{{product.version}}</div>
<div class="product-release-date">{{product.releaseDate}}</div>
</div>
</a>
现在它在角度 5 中完美运行
最有用的评论
我很抱歉。 我仔细查看了我的问题,结果发现我有这段 css 似乎禁用了浏览器中的所有滚动事件
为了解决这个问题,我像这样添加了这个自定义滚动事件
在我的模板中
现在它在角度 5 中完美运行