Skip to content

Instantly share code, notes, and snippets.

@softwarejc
Created January 24, 2016 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save softwarejc/138709a9e42158173022 to your computer and use it in GitHub Desktop.
Save softwarejc/138709a9e42158173022 to your computer and use it in GitHub Desktop.
import {Component} from 'angular2/core';
import {OnInit} from 'angular2/core';
import {HelloService} from './hello.service';
@Component({
// Declare the tag name in index.html to where the component attaches
selector: 'hello',
// Location of the template for this component
templateUrl: 'views/hello.view.html',
// Dependencies
providers: [HelloService]
})
// Component controller
export class Hello implements OnInit {
public message: string;
public name: string;
constructor(private _helloService: HelloService) {
}
ngOnInit() {
this.name = "";
this.message = "";
}
sayHello() {
// Use hello service to call the API and bind result
this._helloService.sayHello(this.name).subscribe(response => {
this.message = response;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment