微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何添加警报 angular11

如何解决如何添加警报 angular11

我只是想做个简单的alert,我找了几个angular 11和alertjs的解决方案,但是比较老了,想通过服务解决我的问题,不使用服务可以解决吗?或者我的错误是什么? angular.json

 "styles": [
          "src/styles.css","./node_modules/bootstrap/dist/css/bootstrap.min.css","./node_modules/font-awesome/css/font-awesome.min.css"
        ],"scripts": [
          "./node_modules/jquery/dist/jquery.min.js","./node_modules/bootstrap/dist/js/bootstrap.min.js"
        ]

component.ts

  import {
    Component,OnInit
  } from '@angular/core';
  import { Product } from './product';
  declare let alertify:any;
  @Component({
    selector: 'app-product',templateUrl: './product.component.html',styleUrls: ['./product.component.css']
  })
  export class ProductComponent implements OnInit {

    constructor() {}
    title = "Ürün Listesi"
    filterText=""
    products: Product[] = [{
        id: 1,name: "Laptop",price: 15,categoryId: 1,description: "Asus Zenbook",imageUrl: "https://picsum.photos/200/100"
      },{
        id: 2,name: "Mouse",price: 25,categoryId: 2,description: "A4Tech",{
        id: 1,];
    emptyProducts = "Ürün Listesi boş"

    ngOnInit(): void {}

    addToCart(product:any){
      alertify.succes("added")
    }

  }
<h3 *ngIf="products; else:noproducts">{{title}}</h3>
<ng-template #noproducts>
  <div class="alert alert-danger" role="alert">
    {{emptyProducts}}
  </div>
</ng-template>
<div class="mb-3">
  <input  [(ngModel)]="filterText" class="form-control" id="productName" placeholder="arama metnini giriniz">
  <div id="text" class="form-text" *ngIf="filterText;else:noText">Şuan <span>{{filterText}} aradınız</span></div>
</div>

<ng-template #noText>

</ng-template>
<div class="row">
  <div *ngFor="let item of products | productFilter:filterText" class="card" style="width: 18rem;">
    <div class="card-body">
      <img [src]="item.imageUrl" class="card-img-top" alt="{{item.name}}">
      <h5 class="card-title">{{item.name | uppercase}} {{item.price| currency:"TRY":"TL":""}} </h5>
      <p class="card-text">{{item.description}}</p>
      <a (click)="addToCart(item)" class="btn btn-primary">Sepete Ekle</a>
    </div>
  </div>

</div>

块引用 错误参考错误:alertify 未定义 块引用

错在哪里

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。