Closed zosmf-Mira closed 4 months ago
@zosmf-Mira, is this even a carbon issue? The error you posted doesn't mention anything related to Carbon components...
It tells you what the issue is in the error message:
error TS2416: Property 'intercept' in type 'ZosmfInterceptorService' is not assignable to the same property in base type 'HttpInterceptor'
Take a look at the InterceptorService and debug.
I fixed this issue and it show no error in console after command "ng s" which means it passed the compiling, however, when I open page in browser, it show below error, could you please help address it because I used almost my all day today but cannot find why it happened.
More info about it is that, message.service work well in "common" project but display this error in browser after passed compiling in "specific" project which used it as a 3rd project. Below is app.components.ts's content: import { Component } from '@angular/core'; import { TranslateService } from '@ngx-translate/core'; // import { MessageService } from './_services/message.service'; import { MessageService } from '../zmf_common/_services/message.service'; import { HttpClient } from '@angular/common/http';
@Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'], providers: [ MessageService] }) export class AppComponent { title = 'zOSMF Diagnostics Assistant'; constructor(public _messageService: MessageService, private http: HttpClient, private translate: TranslateService ){ { translate.addLangs(['en', 'ja']); const browserLang = translate.getBrowserLang(); // console.log("browser languague: " + browserLang); translate.use(browserLang.match(/en|ja/) ? browserLang : 'en').subscribe( data => { this._messageService.setBundle(data.BUNDLE); this._messageService.setMessages(data.MESSAGES);
},
error => {
},
);
} } }
this is message.service.ts's content: import { Injectable, ComponentRef } from '@angular/core'; //import { Headers, RequestOptions } from '@angular/http'; import { HttpClient } from '@angular/common/http'; //import { map, filter, catchError, mergeMap } from 'rxjs/operators'; //import 'bootstrap-notify'; import { AlertService } from './alert.service'; import { ConstantService } from './constant.service'; import { NotificationService, NotificationType, ModalService } from 'carbon-components-angular'; import { MessageInModalsComponent } from '../modal/message-in-modals/message-in-modals.component';
@Injectable({ providedIn: 'root' }) export class MessageService {
public MSG_TYPE_LIST = { SUCCESS : 'success', WARNING : 'warning', DANGER : 'error', INFO : 'info' } public messagePlugin = '';
private messages: object; // loaded from NLS file private bundle: object; // loaded from NLS file
// messageModal: ComponentRef
// private notifies: []; // list of currently displaying notifies
// for local dev // private api_message_url = 'assets/i18n/IZUGMessages.json';
// for vicom dev // TODO: ???
constructor( private http: HttpClient, private _alertService: AlertService, private _constant: ConstantService, private notificationService: NotificationService, protected modalService: ModalService ) { // this.load().subscribe( // data => { // // console.info(data); // this.messages = data; // }, // error => { // alert(JSON.stringify(error)); // this.messages = []; // } // ); }
// public load() { // return this.http.get(this.api_message_url).pipe( // map(res => { // const result = res.json(); // return result; // }), ); // }
public setMessages(messages) { this.messages = messages; }
public getMessage(msgId) { return this.messages[msgId]; }
public getBundle(id) { return this.bundle === undefined ? '' : this.bundle[id]; }
public setBundle(bundle) { this.bundle = bundle; }
public replace(str: string, replacement: Array
private getMsgType(msgId: string): NotificationType { let _type:NotificationType = "success"; if (msgId == null) { } else { let lastChar = msgId.charAt(msgId.length - 1); switch (lastChar) { case "E": _type = "error"; break; case "W": _type = "warning"; break; case "I": _type = "success"; break; default: _type = "success"; } } return _type; }
private getMsgURL(msgId: string, msgPlugin: string): string { return '../../helps/SSB2H8_' + this._constant.getVersion()
'/' + msgPlugin + '/' + msgId + '.html'; }
/**
notificationObj
."info"
, "warning"
, "danger"
, "success"
["arg1", "arg2", ...]
smart
,null
if you don't want the message to auto disappear.true
if you want to use smart notification*/
public notify(msgId: string, replacement: Array
let _type : NotificationType = this.getMsgType(msgId); let _icon = 'assets/img/'; const _url = this.getMsgURL(msgId, this.messagePlugin);
let msgTxt = replacement == null ? this.messages[msgId] : this.replace(this.messages[msgId], replacement);
switch (_type) { case this.MSG_TYPE_LIST.SUCCESS: this._alertService.success(msgId, msgTxt); break; case this.MSG_TYPE_LIST.WARNING: this._alertService.warn(msgId, msgTxt); break; case this.MSG_TYPE_LIST.DANGER: this._alertService.error(msgId, msgTxt); break; default: this._alertService.success(msgId, msgTxt); }
// console.log('<a class="bx--link" href="#" onclick=\'window.open("' + _url // + '", "zosmfHelpWindow", "location=yes, resizable=yes"); return false;\'>' + msgId + ''); this.notificationService.showNotification({ type: _type, // title: '<a class="bx--link" href="#" target="_blank" onclick=\'window.open("' + _url // + '", "zosmfHelpWindow", "location=yes, resizable=yes"); return false;\'>' + msgId + '', title: '' + msgId + '', message: '' + msgTxt + '', target: '.notification-container', duration: duration, smart: smart });
// this.notificationService.showToast({ // type: _type, // title: '<a class="bx--link" href="#" onclick=\'window.open("' + _url // + '", "zosmfHelpWindow", "location=yes, resizable=yes"); return false;\'>' + msgId + ' ', // subtitle: replacement == null ? this.messages[msgId] : this.replace(this.messages[msgId], replacement), // target: '.notification-container', // duration: duration, // smart: smart // }); }
/**
notificationObj
."info"
, "warning"
, "danger"
, "success"
smart
,null
if you don't want the message to auto disappear.true
if you want to use smart notification*/ public addMessage(msgId: string, msgTxt: string, duration: number = 5000, smart: boolean = false) {
let _type = this.getMsgType(msgId); let _icon = 'assets/img/'; const _url = this.getMsgURL(msgId, this.messagePlugin);
switch (_type) { case this.MSG_TYPE_LIST.SUCCESS: this._alertService.success(msgId, msgTxt); break; case this.MSG_TYPE_LIST.WARNING: this._alertService.warn(msgId, msgTxt); break; case this.MSG_TYPE_LIST.DANGER: this._alertService.error(msgId, msgTxt); break; default: this._alertService.success(msgId, msgTxt); }
// console.log('<a class="bx--link" href="#" onclick=\'window.open("' + _url // + '", "zosmfHelpWindow", "location=yes, resizable=yes"); return false;\'>' + msgId + ''); this.notificationService.showNotification({ type: _type, // title: '<a class="bx--link" href="#" target="_blank" onclick=\'window.open("' + _url // + '", "zosmfHelpWindow", "location=yes, resizable=yes"); return false;\'>' + msgId + '', title: '' + msgId + '', message: '' + msgTxt + '', target: '.notification-container', duration: duration, smart: smart });
// this.notificationService.showToast({ // type: _type, // title: '<a class="bx--link" href="#" onclick=\'window.open("' + _url // + '", "zosmfHelpWindow", "location=yes, resizable=yes"); return false;\'>' + msgId + ' ', // subtitle: replacement == null ? this.messages[msgId] : this.replace(this.messages[msgId], replacement), // target: '.notification-container', // duration: duration, // smart: smart // }); }
openMessage(msgId: string, event) { window.open(this.getMsgURL(msgId, this.messagePlugin), 'zosmfHelpWindow', 'location=yes, resizable=yes'); event.preventDefault(); }
/**
notificationObj
."info"
, "warning"
, "danger"
, "success"
["arg1", "arg2", ...]
smart
,null
if you don't want the message to auto disappear.true
if you want to use smart notification*/
public showValidationMessage(msgId: string, replacement: Array
let _type: NotificationType = "success"; let _icon = 'assets/img/'; const _url = this.getMsgURL(msgId, this.messagePlugin);
let msgTxt = replacement == null ? this.messages[msgId] : this.replace(this.messages[msgId], replacement);
// console.log('<a class="bx--link" href="#" onclick=\'window.open("' + _url // + '", "zosmfHelpWindow", "location=yes, resizable=yes"); return false;\'>' + msgId + ''); this.notificationService.showNotification({ type: _type, // title: '<a class="bx--link" href="#" target="_blank" onclick=\'window.open("' + _url // + '", "zosmfHelpWindow", "location=yes, resizable=yes"); return false;\'>' + msgId + '', title: '' + msgId + '', message: '' + msgTxt + '', target: target, duration: duration, smart: smart }); }
/**
}
You're seeing that error in your console because you are NOT providing HttpClient. It is an dependency injection issue. This is a carbon-components-angular repository, your issue is completely unrelated.
By the looks of your previous posts, I can see that you are NOT following Angular's migration guide. Please follow the migration guide here: https://angular.dev/update-guide
Detailed description
Error: node_modules/zmf-common/src/app/_services/zosmf-interceptor.service.ts:42:3 - error TS2416: Property 'intercept' in type 'ZosmfInterceptorService' is not assignable to the same property in base type 'HttpInterceptor'. Type '(req: import("/Users/yuanyuan/Documents/GitHub_UI/zmfui_diagnosis/node_modules/@angular/common/http/index").HttpRequest, next: import("/Users/yuanyuan/Documents/GitHub_UI/zmfui_diagnosis/node_modules/@angular/common/http/index").HttpHandler) => import("/Users/yuanyuan/Documents/GitHub_UI/zmfui_diagnosis/node_mo...' is not assignable to type '(req: import("/Users/yuanyuan/Documents/GitHub_UI/zmfui_diagnosis/node_modules/@angular/common/http/index").HttpRequest, next: import("/Users/yuanyuan/Documents/GitHub_UI/zmfui_diagnosis/node_modules/@angular/common/http/index").HttpHandler) => import("/Users/yuanyuan/Documents/GitHub_UI/zmfui_diagnosis/node_mo...'. Two different types with this name exist, but they are unrelated.
Type 'Observable<HttpEvent>' is missing the following properties from type 'Observable<HttpEvent>': _isScalar, _trySubscribe, _subscribe
42 intercept(req: HttpRequest, next: HttpHandler): Observable<HttpEvent> {