Angular2 ES6 @ Alternative Alternative

I am trying to build a <markdown-component> using ES6 syntax. @Input syntactic sugar @Input not supported in ES6, and I cannot find a viable alternative.

I define the input for the parent with:

 <ng2-markdown [source]="source"></ng2-markdown> 

Then, taking the input using:

 @Component({ selector: 'ng2-markdown', inputs: [ 'source' ] }) 

If I add a template, I can get it, it will output the value as expected, but there will be no way to use the input in the constructor.

This module should be a directive, and the source value will determine the path to the downloaded Markdown file.

+5
source share
1 answer

Thanks to the comment by @Eric Martinez, I was able to get it to work.

Inputs are not available until the OnInit phase of the life cycle.

The following worked:

 ... export class MarkdownComponent { constructor () {} ngOnInit() { console.log(this.source); } ... 

I tried to access the input in the constructor before the inputs were initialized.

+2
source

Source: https://habr.com/ru/post/1239370/


All Articles