Is there any way to assign a json file as a value to @Input directly?
Say i am having config.json as follows,
{
"video": [
{
"videoSrc": "assets/video/test.mp4",
"videoType": "video/mp4",
"videoPlayPause": true,
"videoStartOver": true,
"videoWidth": 300,
"videoHeight": 225
}
],
"image": [
{
"imageSrc": "assets/image/test.jpg",
"imageType": "jpg",
"imgWidth": 300,
"imgHeight": 225
}
]
}
In video-component i am in the need to get the video object from the file,
In video-component.ts i have the following code,
import { Component, OnInit, Input, ViewChild } from '@angular/core';
@Component({
selector: 'mrt-video-playback',
templateUrl: './video-playback.component.html',
styleUrls: ['./video-playback.component.scss']
})
export class VideoPlaybackComponent implements OnInit {
@Input() videoConfiguration: object = config.json;
}
In html i have,
<div> {{videoConfiguration}} </div>
I know that the below line is wrong,
@Input() videoConfiguration: object = config.json;
But i am given one such thing that i should get the object from json and need to store it to @Input.
In config.json file i need to get the video object and need to pass it to html as it is video component i am in the need to pass the values from video to the html. As i have used @Input, it can also be used in other component.
JSON.parsethe file and pass that as input