angularjs - Angular 2 using both typescript and javascript -
i have angular 2 application written on javascript. want migrate typescript.
js code is:
(function (app) { app.someservice = ng.core .class({ constructor: [app.anotherservice, function someservice(s) { this._anotherservice = s; }], somefunction: function(){ ... } ..... }); }) (window.app || (window.app = {}));
i want inject service typescript component. how can that?
i tried use this:
@component({...}) export class somecomponent { constructor(public someservice: window.app.someservice) { } }
but not work.
the way i've managed mix js , ts have file js, in case let's it's src/app.js , code posted above.
at point can 1 of 2 things:
you create component going use said js code, like:
import {component} "angular2/core"; @component({ selector: 'app', template: ` <a> <onclick='app()'>when function clicked, use app() code</a> , directives: [] }) export class app { constructor(){ } }
the template going depend on code supposed do. use onclick, here have example of might like:
template: `<input value="select date" type="text" class="datepicker" onclick ="mycalendar()" >
`
another option call js code constructor
import {component} 'angular2/core'; @component({ selector: 'app', template: ` <div> </div> `, directives: [] }) export class myapp { name:string; constructor() { this.name='angular 2'; app(); } }
so depends on want do, , when, far can tell. there people more experience tried not wrong, , provide code similar have working right now.
Comments
Post a Comment