wal*_*ali 2 angular-cli angular-toastr angular
我想在我的角度2应用程序中使用ng2-toastr.我已按照所有说明操作,但toastr无法显示没有任何控制台错误.我还读过一些地方,ng-toastr不再适用于角度2,但没有找到任何有效的文档.我搜索了类似的问题,但没有找到任何合适的答案来解决我的问题.任何帮助,将不胜感激.
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router';
import{ ToastModule} from 'ng2-toastr/ng2-toastr';
import { BrowserAnimationsModule} from '@angular/platform-
browser/animations';
import "hammerjs"
import { CoreModule } from './core/core.module';
import { MODULE_ROUTES, MODULE_COMPONENTS } from './app.router'
@NgModule({
declarations: [
MODULE_COMPONENTS
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
RouterModule.forRoot(MODULE_ROUTES),
BrowserAnimationsModule,
CoreModule,
ToastModule.forRoot()
],
providers: [ ],
bootstrap: [MODULE_COMPONENTS]
})
export class AppModule { }
Run Code Online (Sandbox Code Playgroud)
app.component.ts
import { Component, ViewContainerRef } from '@angular/core';
import { ViewEncapsulation } from '@angular/core';
import { ToastsManager } from 'ng2-toastr/ng2-toastr';
@Component({
selector: 'wow-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
encapsulation: ViewEncapsulation.None
})
export class AppComponent {
constructor( public toastr: ToastsManager, private vRef: ViewContainerRef)
{
this.toastr.setRootViewContainerRef(vRef);
console.log(this.toastr);
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我在我的一个组件中调用toastr方法的方法:
login() {
this.user_service.login(this.user).then((response) => {
console.log(response)
this.toastrManager.success('Successfully Logged in.')
}
Run Code Online (Sandbox Code Playgroud)
的package.json
"dependencies": {
"@angular/animations": "^4.1.3",
"@angular/common": "^4.0.0",
"@angular/compiler": "^4.0.0",
"@angular/core": "^4.0.0",
"@angular/forms": "^4.0.0",
"@angular/http": "^4.0.0",
"@angular/platform-browser": "^4.0.0",
"@angular/platform-browser-dynamic": "^4.0.0",
"@angular/router": "^4.0.0",
"angular2-image-upload": "^0.6.1",
"core-js": "^2.4.1",
"hammerjs": "^2.0.8",
"jquery": "^3.2.1",
"ng2-toastr": "^4.1.2",
"rxjs": "^5.1.0",
"zone.js": "^0.8.4"
},
"devDependencies": {
"@angular/cli": "1.0.3",
"@angular/compiler-cli": "^4.0.0",
"@types/jasmine": "2.5.38"
}
Run Code Online (Sandbox Code Playgroud)
我还添加"../node_modules/ng2-toastr/bundles/ng2-toastr.min.css"了我的angular-cli.json.这是console.log
在angular-cli.json文件中,在styles属性中添加此行
../node_modules/ng2-toastr/bundles/ng2-toastr.min.css
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4236 次 |
| 最近记录: |