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>' |
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', { | |
bindings: { | |
name: '@', // String binding | |
age: '<', // One-way binding | |
color: '@favouriteColor' // Renamed string binding | |
}, | |
controller() { | |
this.name = this.name || 'User'; // Default value |
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', { | |
bindings: { | |
buttonClick: '&' | |
}, | |
controller() { | |
this.clickCount = 0; | |
this.onButtonClick = () => { | |
this.buttonClick({clicks: ++this.clickCount}); |
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 | |
import NumberService from './path/to/number-service'; | |
const module = angular.module('myModule', []); | |
module.service('NumberService', () => NumberService); | |
module.component('myComponent', { | |
controller: ['NumberService', function (numberService) { | |
this.value = numberService.random(1, 100); | |
}, | |
template: ` |
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', { | |
template: ` | |
<label for="name">Your Name</label> | |
<input id="name" name="name" ng-model="$ctrl.name" /> | |
` | |
}); | |
/***************************************************************/ |
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', { | |
template: ` | |
<form name="myForm"> | |
<label for="name">Your Name</label> | |
<input id="name" name="name" ng-model="$ctrl.name" required /> | |
<div ng-if="myForm.name.$error">Name is Required</div> | |
</form> | |
` |
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.filter('kebabCase', () => (input) => input.toLowerCase().replace(' ', '-')); | |
/***************************************************************/ | |
// Angular 2 | |
import {Pipe, PipeTransform} from '@angular/core'; | |
@Pipe({name: 'kebabCase'}) |
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', [ModuleB, ModuleC]); | |
module.component('myComponent', MyComponent); | |
module.service('myService', MyService); | |
/***************************************************************/ | |
// Angular 2 | |
import { NgModule } from '@angular/core'; |
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.service('UserService', ['$http', function ($http) { | |
this.getUsers = () => { | |
// Code to retrieve users here | |
} | |
}]); |
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.service('MyService', MyService); | |
module.factory('MyFactory', MyFactory); | |
module.value('MyValue', MyValue); | |
/***************************************************************/ | |
// Angular 2 | |
import { NgModule } from '@angular/core'; |