Last active
May 21, 2018 12:21
-
-
Save eddytseng/72f355dc9a64204a43080dcc9313e343 to your computer and use it in GitHub Desktop.
Angularjs counter component
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
| function CounterController() { | |
| this.increment = function() { | |
| this.count++; | |
| }; | |
| this.decrement = function() { | |
| this.count--; | |
| }; | |
| } | |
| angular | |
| .module('app') | |
| .controller('CounterController', CounterController); |
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
| function counter() { | |
| return { | |
| scope: {}, | |
| bindToController: { | |
| count: '=' | |
| }, | |
| controller: 'CounterCtrl as counter', | |
| template:` | |
| <div>{{ counter.count }}</div> | |
| <div> | |
| <button ng-click="counter.decrement();">-</button> | |
| <button ng-click="counter.increment();">+</button> | |
| </div> | |
| ` | |
| }; | |
| } | |
| angular | |
| .module('app') | |
| .directive('counter', counter); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment