zoukankan      html  css  js  c++  java
  • [Angular 2] Inject Service

    TypeScript is used heavily as we build up our application, but TypeScript isn’t required. If you want to Inject a Service without using TypeScript, you’ll need to understand the @Inject decorator.

    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);
        }
    }
  • 相关阅读:
    mysql-03
    mysql-02
    mysql-01
    RESTFUL设计风格
    mysql水平拆分和垂直拆分
    redis连环夺命问
    Python 的十大重要特性
    吊打--redis
    python2和3 的区别
    tornado第一段代码
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4904687.html
Copyright © 2011-2022 走看看