I'm new to Angular 2.0 and have been working on new things to learn it. Since this is very common problem which I have seen, after reading a lot of answers I still did not reach to my solution. My problem is I'm trying to put the date object in the interface which contains certain elements. After trying to enter the date object still I'm getting the error.
MyCode shown below:
export class Lesson {
id: number
name: string
image_url: string
start_time: Date
end_time: Date
}
In my typescript I'm trying to enter the dummy data, for every elements it is fine but when it comes to start_time and end_time it is giving me this error always : Unexpected token. A constructor, method, accessor, or property was expected.
The code goes like this in my typescript file :
export class MyClassesComponent implements OnInit {
var date = '2017-11-27T09:10:00';
var time = new Date(date);
lesson : Lesson = {id: 10, name: "Test Lesson", image_url: "abc", start_time: time, end_time: time}
constructor() { }
ngOnInit() {
}
}
Since I've tried a lot and tried these things also which is not fruitful :
var date = '2017-11-27T09:10:00';
Date time = new Date(date);
for this I got something like this :
Class 'MyClassesComponent' incorrectly implements interface 'OnInit'. Property 'ngOnInit' is missing in type 'MyClassesComponent'.
Please treat me as a learner and help. Since I've tried but don't know how to tackle this. Any help would be highly appreciated. Thanks.
Note: Since this code has to work in the typescript itself I'm working on it right now. So need help in this section only.
Another point for those who might think the problem must be due to the importing stuff. For this I've already done my homework and everything is imported, it is just that I have to pass the date object in the start_time and end_time. import {Component, OnInIt} from '@angular/core'