我有一个Typescript编译问题.此代码返回错误:
错误TS2304:找不到名称'NavigationEnd'.
如何让编译器了解NavigationEnd类型?NavigationEnd是angular2路由器事件类型.
this.router.events.subscribe((e) => {e instanceof NavigationEnd ?
console.log('NavigationEnd'):console.log('Not NavigationEnd')});
Run Code Online (Sandbox Code Playgroud)
我正在使用IDE PHPStorm.
我想在我的应用程序中使用PrimeNG日历.当我运行代码时,我收到错误:
ReferenceError:未定义jQuery.
其他PrimeNG指令工作正常.如果我删除<p-calendar>错误消失.
我在我的应用中导入并包含了日历.顺便说一下,我正在使用最新版本的角度,路由器和表格.在此之前我遇到了这个问题,并通过更新表单提供程序来修复它
<p-calendar [(ngModel)]="date"></p-calendar>
Run Code Online (Sandbox Code Playgroud)
Stacktrace摘录:
ReferenceError:在DebugAppView._View_AddShipmentComponent0.detectChangesInternal(AddShipmentComponent.template.js)的Calendar.ngAfterViewInit(eval at(http:// localhost:8080/js/app.js:930:2),:44:90)中未定义jQuery. :930:59)在DebugAppView.Appte.detectChanges(eval at(http:// localhost:8080/js/vendor.js:716:2),:243:14)在DebugAppView.detectChanges(eval at(http:/) /localhost:8080/js/vendor.js:716:2),:348:44)
我创建了CustomHttp类,它扩展了Http,如下所示:http://restlet.com/blog/2016/04/18/interacting-efficiently-with-a-restful-service-with-angular2-and-rxjs-part-3/ #评论- 83563
我将提供程序添加到bootstrap中,如下所示:
bootstrap([
HTTP_PROVIDERS,
{ provide:Http,
useFactory: (backend: XHRBackend, defaultOptions: RequestOptions, errorNotifier: NotificationHandlerService,
authService: AuthInfoService) => {
return new CustomHttp(backend, defaultOptions, errorNotifier, authService);
},
deps: [ XHRBackend, RequestOptions, NotificationHandlerService, AuthInfoService]
},
])
Run Code Online (Sandbox Code Playgroud)
所有重写方法(get,post等)都可以正常工作.然后我将自定义属性和方法添加到CustomHttp类并尝试访问CustomHttp外部的属性:
@Injectable()
export class CustomHttp extends Http {
...
private myCustomProperty = 'It`s custom';
public getCustomProperty() {
return this.myCustomProperty;
}
...
}
Run Code Online (Sandbox Code Playgroud)
=====================
import {Http} from '@angular/http';
export class MainComponent {
constructor(private _http: Http) {
this._http.getCustomProperty(); // this method doesn`t exist in Http
} …Run Code Online (Sandbox Code Playgroud)