javascript – (Angular2)无法读取toastr的undefined属性’extend’
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – (Angular2)无法读取toastr的undefined属性’extend’,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1583字,纯文字阅读大概需要3分钟。
内容图文
![javascript – (Angular2)无法读取toastr的undefined属性’extend’](/upload/InfoBanner/zyjiaocheng/766/23d8df2925ae495c8b5fe5371504d756.jpg)
我正在尝试在angularjs 2中使用toastr作为服务,将在我的组件中注入,如下所述.当调用handleEvent函数时,我正在接收“无法读取未定义的属性’扩展’”.非常感谢对错误的任何建议和/或解释.
app.moudle.ts已导入ToastrService,并且已在提供程序中添加ToastrService.
//events/events-list.components.ts
import { ToastrService } from '../common/toastr.service';
@Component ({
selector: 'event-list',
template: `
<div>
<h1> Upcoming Angular 2 Event </h1>
<hr>
<div class="row">
<div *ngFor="let event_data of all_data" class="col-md-5">
<event-thumbnail (click)="handleEvent(event_data.name)" [event]="event_data"></event-thumbnail>
</div>
</div>
</div>
`
})
export class EventListComponent implements OnInit {
all_data:any[]
constructor(private eventService : EventService , private toastr : ToastrService ){
//moved code from here to ngOnInit
}
ngOnInit(){
this.all_data = this.eventService.getEvents();
}
handleEvent(eventName) {
console.log("hey here "+eventName);
this.toastr.success(eventName);
}
}
错误:
[在console.log输出后抛出此错误]
EXCEPTION: Error in ./EventListComponent class EventListComponent –
inline template:6:16 caused by: Cannot read property ‘extend’ of
undefined.
ORIGINAL EXCEPTION: Cannot read property ‘extend’ of undefined
TypeError: Cannot read property ‘extend’ of undefined
at m (toastr.js:411)
at Object.s [as success] (toastr.js:85)
at ToastrService.success (toastr.service.ts:12)
解决方法:
加上这个
script src =“node_modules / toastr / build / toastr.min.js”
在这之后
script src =“node_modules / jquery / dist / jquery.min.js”>< / script>
原因:toastr.js使用jQuery,因此jQuery应该在toastr.js之前加载
内容总结
以上是互联网集市为您收集整理的javascript – (Angular2)无法读取toastr的undefined属性’extend’全部内容,希望文章能够帮你解决javascript – (Angular2)无法读取toastr的undefined属性’extend’所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。