TypeScript is used heavily as we build to our application, but TypeScript isn ' t required. If you want to Inject a Service without using TypeScript, you'll need to understand the decorator @Inject
.
Import {Component, View, Inject} from "Angular2/angular2"; Import {Todoservice} from"./todoservice"; @Component ({selector:' Todo-input '})//Define a ref by using XXX-YYY//Reference a ref by using XXXYYY@View ({Template: '<input type= "text" #log-me/> <button (click) = "OnClick ($event, Logme.value)" >log input</button> `}) Export class todoinput{ todoservice; Constructor (//Public Todoservice:todoservice//pulbic make Todoservice Global available for the class @Inject (todoservice) todoservice; ) {Console.log (todoservice); } onClick (event, value) { This. Todoservice.addtodo (value); Console.log ( This. Todoservice.todos); }}
[Angular 2] Inject Service