Created
November 13, 2016 08:45
-
-
Save jrwebdev/2611ecd060acb2db0fc7281f1537b903 to your computer and use it in GitHub Desktop.
Angular 1 vs Angular 2 Component Properties & Methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Angular 1 | |
| const module = angular.module('myModule', []); | |
| module.component('myComponent', { | |
| controller() { | |
| this.message = 'Hello World!'; | |
| this.sayHello = () => { | |
| alert('Hello World!'); | |
| }; | |
| }, | |
| template: '<div ng-click="$ctrl.sayHello()">{{$ctrl.message}}</div>' | |
| }); | |
| /***************************************************************/ | |
| // Angular 2 | |
| import {Component} from '@angular/core'; | |
| @Component({ | |
| selector: 'my-component', | |
| template: '<div (click)="sayHello()">{{message}}</div>' | |
| }) | |
| class MyComponent { | |
| message: string = 'Hello World!'; | |
| sayHello() { | |
| alert('Hello World!'); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment