我正在使用 stackblitz 处理 angular 文档,并且到目前为止它让我创建的两个 window.alert 都不起作用。第一个是“共享”按钮,实际上只是我将它添加到 HTML 中,但是当我单击共享按钮时警报不起作用。有关故障排除的任何提示?
这是组件:
import { Component } from '@angular/core';
import { products } from '../products';
@Component({
selector: 'app-product-list',templateUrl: './product-list.component.html',styleUrls: ['./product-list.component.css']
})
export class ProductListComponent {
products = products;
share() {
window.alert('The product has been shared!');
}
onNotify() {
window.alert('You will be notified when the product goes on sale');
}
}
这是html:
<h2>Products</h2>
<div *ngFor="let product of products">
<h3>
<a [title]="product.name + ' details'">
{{ product.name }}
</a>
</h3>
<p *ngIf="product.description">
Description: {{ product.description }}
</p>
<button (click)="share()">
Share
</button>
<app-product-alerts [product]="product" (notify)="onNotify()">
</app-product-alerts>
</div>