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: ` | |
| <div | |
| ng-if="$ctrl.isShown" | |
| ng-click="$ctrl.onClick($event)" | |
| ng-class="{blue: $ctrl.isBlue}"> | |
| Hello World! |
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 = () => { | |
| return $http.get('http://api.mywebsite.com/users') | |
| .then(res => res.data) | |
| .catch(res => new Error(res.data.error)); | |
| } |
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'; |
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', [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.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', []); | |
| 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.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 | |
| 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', { | |
| bindings: { | |
| buttonClick: '&' | |
| }, | |
| controller() { | |
| this.clickCount = 0; | |
| this.onButtonClick = () => { | |
| this.buttonClick({clicks: ++this.clickCount}); |