如何将Toastr导入角度应用程序?
我正在学习Angular Fundamentals课程,并试图从我的 $query = mysql_query("SELECT * FROM `cpgq7_pictures` WHERE aid=$album_id ORDER BY ctime DESC LIMIT 0 , 3");
echo 'document.write(\'';
if(mysql_num_rows($query) == 0){
echo 'No hay fotos';
} else {
echo '<h6>';
while($row = mysql_fetch_array($query)){
$domain = "http://linklink.net/cpg";
$album_url = "$domain/thumbnails.php?album=$album_id#content";
$album_img = "$domain/albums/".$row['filepath'].'thumb_'.$row['filename'];
echo '<a href="'.$album_url.'" target="_blank"><img src="'.$album_img.'" alt="" /></a>';
}
echo '<a href="'.$album_url.'" target="_blank"><img src="https://i.imgur.com/4wmomUt.png" alt="" /></a></h6>';
}
echo '\');';
中简单显示 toastr.success :
export class
并出现以下错误:
完整的handleThumbnailClick(eventName){
toastr.success(eventName)
}
文件是:
ts
我已经运行过此程序来安装toastr:
import { Component, OnInit } from '@angular/core'
import { EventService } from './shared/event.service'
declare let toastr
@Component({
selector: 'events-list',
template: `<div>
<h1>upcoming angular components</h1>
<hr>
<div class="row">
<div class="col-md-5" *ngFor="let event of events">
<event-thumbnail (click)="handleThumbnailClick(event.name)" [event]="event"></event-thumbnail>
</div>
</div>
</div>`})
export class EventsListComponent implements OnInit {
events:any[]
constructor(private eventService: EventService) {
}
ngOnInit() {
this.events = this.eventService.getEvents()
}
handleThumbnailClick(eventName){
toastr.success(eventName)
}
}
并且已将它们包括在npm install toastr --save
文件中:
我在做什么错?为什么不敬酒渲染?
答案 0 :(得分:2)
使用此导入语句
import * as toastr from 'toastr';
代替
declare let toastr
和您的angular.json
,应该是这样
"styles": [
"src/styles.css",
"../node_modules/toastr/build/toastr.min.css"
],
"scripts": [
"../node_modules/toastr/build/toastr.min.js"
]