Я знаю, что c8yDataModule находится в бета-версии, но все же я могу его использовать. Я использовал этот c8yDataModule в одном приложении, но он не работает в другом приложении, и я получаю много ошибок.
Я импортировал модуль C8yDataModule в мое приложение angular6, как показано ниже, а затем в импорт и экспорт я добавил его.
импорт {C8yDataModule} из '@ c8y / ngx-data';
Ошибка говорит о corss-fetch и некоторых других ошибках. Поэтому я также собрал билет в перекрестной загрузке, и авторы говорят, чтобы проверить последнюю версию corss-fetch.
Помимо этого, появляются и другие ошибки, поэтому я прошу вас проверить эти ошибки и направить нас.
https://github.com/lquixada/cross-fetch/issues/22
ERROR in node_modules/@c8y/ngx-data/node_modules/@c8y/client/lib/src/core/FetchClient.d.ts(1,29): error TS7016: Could not find a declaration file for module 'cross-fetch'. 'C:/Projects/angular-its-code/node_modules/cross-fetch/dist/node-ponyfill.js' implicitly has an 'any' type.
Try `npm install @types/cross-fetch` if it exists or add a new declaration (.d.ts) file containing `declare module 'cross-fetch';`
node_modules/@c8y/ngx-data/node_modules/@c8y/client/lib/src/core/IAuthentication.d.ts(10,5): error TS2411: Property 'tenant' of type 'string | undefined' is not assignable to string index type 'string'.
node_modules/@c8y/ngx-data/node_modules/@c8y/client/lib/src/core/IAuthentication.d.ts(11,5): error TS2411: Property 'user' of type 'string | undefined' is not assignable to string index type 'string'.
node_modules/@c8y/ngx-data/node_modules/@c8y/client/lib/src/core/IAuthentication.d.ts(12,5): error TS2411: Property 'password' of type 'string | undefined' is not assignable to string index type 'string'.
node_modules/@c8y/ngx-data/node_modules/@c8y/client/lib/src/core/IAuthentication.d.ts(13,5): error TS2411: Property 'token' of type 'string | undefined' is not assignable to string index type 'string'.
node_modules/@c8y/ngx-data/node_modules/@c8y/client/lib/src/core/IAuthentication.d.ts(14,5): error TS2411: Property 'tfa' of type 'string | undefined' is not assignable to string index type 'string'.
node_modules/@c8y/ngx-data/node_modules/rxjs/internal/symbol/observable.d.ts(4,9): error TS2687: All declarations of 'observable' must have identical modifiers.
Спасибо
BA
{
"name": "frontend",
"version": "4.0.0",
"license": "MIT",
"browserslist": [
"dead"
],
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build --prod",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.1.0",
"@angular/common": "^6.1.0",
"@angular/compiler": "^6.1.0",
"@angular/core": "^6.1.0",
"@angular/forms": "^6.1.0",
"@angular/http": "^6.1.0",
"@angular/platform-browser": "^6.1.0",
"@angular/platform-browser-dynamic": "^6.1.0",
"@angular/router": "^6.1.0",
"@c8y/ngx-components": "0.0.2-beta2",
"core-js": "^2.5.4",
"rxjs": "^6.0.0",
"rxjs-compat": "6.2.2",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.6.8",
"@angular/compiler-cli": "^6.1.7",
"@angular/language-service": "^6.1.7",
"@angular/platform-browser": "^6.1.0",
"@c8y/ngx-components": "0.0.2-beta1",
"@types/jasmine": "^2.8.8",
"@types/jasminewd2": "~2.0.2",
"@types/node": "^10.9.4",
"angular-translate": "^2.18.1",
"codelyzer": "^4.4.4",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^2.0.5",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^1.4.3",
"karma-jasmine": "^1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "^7.0.1",
"tslint": "~5.9.1",
"typescript": "^2.9.2"
}
}
// angular core
import {NgModule, ErrorHandler} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {FormsModule} from '@angular/forms';
import {HttpClientModule, HttpClient, HTTP_INTERCEPTORS} from '@angular/common/http';
import {TranslateModule, TranslateLoader} from '@ngx-translate/core';
// app modules / services / constants / ...
import {AppComponent} from './app.component';
import {AppRoutingModule} from './app.routing';
import {AlertComponent} from './shared/components/alert.component';
import {AuthGuard} from './core/auth/auth.guard';
import {JwtInterceptor} from './core/http/jwt.interceptor';
import {CatchErrorInterceptor} from "./core/http/catch-error.interceptor";
import {AlertService} from './shared/services/alert.service';
import {AuthenticationService} from './shared/services/authentication.service';
import {InlineEditService} from "./shared/services/inline-edit.service";
import {UserService} from './shared/services/user.service';
import {SideNavService} from "./layouts/main-layout/services/side-nav.service";
import {LoginModule} from './modules/login/login.module';
import {createTemparTranslateLoader} from "./core/i18n/tempar-translation-loader";
import { CumulocityService } from '../app/shared/services/c8y.service';
import { C8yDataModule } from '@c8y/ngx-data';
export class UIErrorHandler extends ErrorHandler {
constructor() {
super();
}
handleError(error: any) {
super.handleError(error);
alert(`Error occurred:${error.message}`);
}
}
@NgModule({
declarations: [
AppComponent,
AlertComponent,
],
imports: [
// core
BrowserModule,
FormsModule,
HttpClientModule,
// routing
AppRoutingModule,
// app
LoginModule,
C8yDataModule,
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: createTemparTranslateLoader,
deps: [HttpClient]
}
})
],
providers: [
AuthGuard,
AlertService,
AuthenticationService,
SideNavService,
UserService,
InlineEditService,
CumulocityService,
// {
// provide: ErrorHandler,
// useClass: UIErrorHandler
// },
{
provide: HTTP_INTERCEPTORS,
useClass: JwtInterceptor,
multi: true
},
{
provide: HTTP_INTERCEPTORS,
useClass: CatchErrorInterceptor,
multi: true
}
],
bootstrap: [
AppComponent,
],
exports: [
C8yDataModule
]
})
export class AppModule {
}
authentication.service.ts.
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { environment } from '../../../environments/environment';
import { User } from "../../models/user";
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { CumulocityService } from './c8y.service';
@Injectable()
export class AuthenticationService {
loggedIn: boolean = false;
isAdmin: boolean = false;
token: string | null = null;
username: string = '';
alarms:any = [];
private API_ENDPOINTS = {
// login: '/user/login',
login: 'user/currentUser?auth'
}
constructor(private http: HttpClient, public cumulocityService:CumulocityService) {
console.log("cumulocityService", this.cumulocityService.client);
debugger;
this.cumulocityService.client.alarm.list$().subscribe((data) => this.alarms = data);
this.loadToken();
}
}
c8y.service.ts - На самом деле я взял это из вашего примера, который вы уже дали в другом вопросе. Тот же код, который я взял из этого примера скрипки.
import { Injectable } from '@angular/core';
import { Client } from '@c8y/client';
@Injectable()
export class CumulocityService {
public client: Client;
constructor() {}
}
версия
npm - версия
5.6.0
узел - версия
v8.11.3