Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jrwebdev/2611ecd060acb2db0fc7281f1537b903 to your computer and use it in GitHub Desktop.

Select an option

Save jrwebdev/2611ecd060acb2db0fc7281f1537b903 to your computer and use it in GitHub Desktop.
Angular 1 vs Angular 2 Component Properties & Methods
// 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