Skip to content

Instantly share code, notes, and snippets.

@eddytseng
Last active May 21, 2018 12:21
Show Gist options
  • Select an option

  • Save eddytseng/72f355dc9a64204a43080dcc9313e343 to your computer and use it in GitHub Desktop.

Select an option

Save eddytseng/72f355dc9a64204a43080dcc9313e343 to your computer and use it in GitHub Desktop.
Angularjs counter component
function CounterController() {
this.increment = function() {
this.count++;
};
this.decrement = function() {
this.count--;
};
}
angular
.module('app')
.controller('CounterController', CounterController);
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