Reputation: 679
I had a simple component in my angular project till I recently made some changes with my package.json, downgraded from 4.2.4 to 4.1.3, did npm install then returned back to 4.2.4... and now I'm getting this error when building the project:
$ ng build Your global Angular CLI version (1.5.0) is greater than your local version (1.4.9). The local Angular CLI version is used.
To disable this warning use "ng set --global warnings.versionMismatch=false". Date: 2018-02-22T11:38:57.826Z Hash: 60271d03b90ff65e3d81 Time: 3114ms chunk {inline} inline.bundle.js, inline.bundle.js.map (inline) 5.83 kB [entry] [rendered] chunk {main} main.bundle.js, main.bundle.js.map (main) 303 bytes [initial] [rendered] chunk {polyfills} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 323 bytes {inline} [initial] [rendered] chunk {styles} styles.bundle.js, styles.bundle.js.map (styles) 11.3 kB {inline} [initial] [rendered]
ERROR in C:/workspace/DataFab/dev/ResourcesManagement/web/ResourceManagerWebClient/src/app/components/about/about.component.ts (16,49): Property 'text' does not exist on type '{} | Response'. Property 'text' does not exist on type '{}'.
the component:
import { Component, OnInit, EventEmitter } from '@angular/core';
import { ResourcesService } from '../../services/resources.service';
@Component({
selector: 'app-about',
templateUrl: './about.component.html',
styleUrls: ['./about.component.css']
})
export class AboutComponent implements OnInit {
version;
constructor(private resourcesService: ResourcesService) {
this.version = resourcesService.getVersion()
.subscribe( data => this.version = data.text(), error => console.log(error) ).toString();
}
How can revert back? Is it related to angular version? npm version?
I updated npm to the latest version but it didnt help:
$ npm -v 5.6.0
Thanks.
Upvotes: 0
Views: 328
Reputation: 1723
this.version = resourcesService.getVersion()
.subscribe( data => this.version = data.text(), error => console.log(error) ).toString(); }
It's related just to typing.
Just add type :any to data:
this.version = resourcesService.getVersion()
.subscribe( data:any => this.version = data.text(), error => console.log(error) ).toString();
}
You also may use Interfaces to typing your responses, like:
export interface ResponseI {
text: string;
something: any;
}
And the use it in your service:
return this.http.get<ResponseI>(...);
In that case you should not define data as any type and may just use it like in your example:
this.version = resourcesService.getVersion()
.subscribe( data => this.version = data.text(), error => console.log(error) ).toString();
}
And one more. Better code would be:
resourcesService.getVersion()
.subscribe( data:any => this.version = data.text(), error =>
console.log(error) );
Upvotes: 1