We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.
The conversion logic can be changed, so this should also work with Date objects...
Hey, not sure if anyone is still running into this, but you can avoid messing with the property decoration pain by simply wrapping your input variable in brackets. So instead of writing your html element like so: <my-component [enabled]="false"></my-component> Simply use: And Angular2+ should recognize the input as the correct type(boolean). Thanks, Max
Yes, of course this is possible. The described technique tries to avoid problems when users miss the brackets or can be used to add transformation logic...
Good source. I would appreciate some examples as well. Not sure what is wrong but when I tried to create my own decorator and trying to access the the Object the
this [key] is undefined as well as when I call Object.getOwnPropertyDescriptor(target, key); I get nothing.
not sure what I am doing wrong so some plunkr would be great inspiration.
Just tried it with the latest Angular 2 release and it still works for me.
Thanks for your comment. As soon as I find the time, I'll add a sample project or a plunkr. Maybe it is not working with the latest Angular 2 release?
Not sure I just started to debug it. but simple straigh forward fails. Its so simple that nothing cant go wrong.
export function Test() {
return function (target: Object, key: string) {
var _val = this[key]; console.log('target: ' + _val);
var ownPropertyDescriptor = Object.getOwnPropertyDescriptor(target, key);
console.log('target2: ' + ownPropertyDescriptor);
}
}
You must put inputs between [] to work properly.
Instead of enabled="false" write [enabled]="false"
Then angular2 sets a boolean value without the need of the custom decorator.
great it works :)
Rico Suter, thank you for this article.
Isidoro Aguilera, thank you for your comment.
Thanks for your comment. However, not all users of your component may know this and therefore using the converters is more safe...
Thanks so much.. ran into same issue.. appreciate if you could provide a plunkr or github source code. Many Thanks Prasad
Haven't tried it yet myself, but is there any reason this can't be used to convert to a "new Date()" object? Kendo datepicker requires a Date object for input, and something like this would be helpful.