I'm encountering issues with Angular 4. The TypeScript code is not compiling and generating errors when I try to run ng serve
.
I'm getting two errors in my-data.service.ts file - "Cannot find name 'Category' at line 9, column 30" and "Cannot find name 'Category' at line 13, column 17"
my-data.service.ts
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import { Observable } from 'rxjs';
@Injectable()
export class MyDataService {
database:string = 'http://localhost/exploremo2/material/database/';
database2:string = 'http://192.168.254.105/exploremo2/material/database/';
constructor(private http: Http) {}
getCategories(): Observable<Category[]>{
return this.http.get(this.database+'getdata/getallcategory.php')
.map(res => {
return res.json().results.map(item => {
return new Category(item);
});
});
}
}
add.component.ts
import { Component, OnInit } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { fadeInAnimation } from '../_animations/fadein';
import { slideInOutAnimation } from '../_animations/slide';
import { MyDataService} from '../my-data.service';
import { Observable } from 'rxjs';
@Component({
selector: 'app-add',
templateUrl: './add.component.html',
styleUrls: ['./add.component.css','../app.component.css'],
providers: [Title],
animations: [slideInOutAnimation],
})
export class AddComponent implements OnInit {
private Categories:Observable<any>;
constructor( private title: Title, private MyDataService:MyDataService) {
this.title.setTitle('Add');
}
ngOnInit() {
this.Categories = this.MyDataService.getCategories();
}
}