angular - Angular2 How to Define Input Property in Plain JS -
i want specify input property component using plain js (not typescript).
the documentation can find (which angular2 cheat sheet):
ng.core.input(myproperty, mycomponent); //declares input property can //update via property binding (e.g. <my-cmp [my-property]="someexpression">). i've tried in component's constructor:
.class({ constructor: function () { ng.core.input(this.name, this); } }); however, not work (no errors reported either).
what doing wrong?
for these cases have inputs , outputs properties. note ts case annotations singular (input , output) , plain js they're plural (inputs , outputs).
var children = ng.core. component({ inputs : ['myvalue'], // equivalent @input('myvalue') outputs : ['emitvalue'] // equivalent @output() emitvalue; }). class({ constructor: function() { // initialize emitvalue this.emitvalue = new ng.core.eventemitter(); }, // available @ ngoninit lifecycle ngoninit : function() { console.log(this.myvalue); }, // value component emit emit : function() { this.emitvalue.emit('this value children'); } }); with inputs can use syntax [internalvalue: externalvalue], give possibility this
<another-cmp [externalvalue]="someexpression"></another-cmp> .component({ inputs : ['internalvalue: externalvalue'] }) .class({ ngoninit : function() { // 'internalvalue' contains 'externalvalue' value console.log(this.internalvalue); } }) and parent component
var parent = ng.core. component({ selector: 'cmp', template : ` <another-cmp [myvalue]="myvalue" (emitvalue)="printvalue($event)"> </another-cmp> children have say? {{childrenvalue}} `, directives : [children] }). class({ constructor: function() { this.myvalue = 'some value pass children'; }, printvalue : function(value) { this.childrenvalue = value; } }); here's plnkr demonstrating case. hope helps.
Comments
Post a Comment