Skip to content

Instantly share code, notes, and snippets.

@ryepup
Last active August 29, 2015 14:15
Show Gist options
  • Save ryepup/287bbebf898aed7fe4a5 to your computer and use it in GitHub Desktop.
Save ryepup/287bbebf898aed7fe4a5 to your computer and use it in GitHub Desktop.
component directive
<div>
<pre>{{vm.ngModel|json}}</pre>
<button ng-click="vm.save()" ng-disabled="vm.saving">Save</button>
</div>
angular.module('my-app')
.directive('my-component', function() {
return {
templateUrl: 'my-component.html',
// put logic in a controller, available to the view as `vm`
controller: 'MyComponentCtrl as vm',
// inputs to the component
scope: { ngModel:'=' },
// bind inputs directly to the controller
bindToController: true
};
})
.controller('MyComponentCtrl', function(MyService) {
// initialize the controller, create functions for the template
var vm = this;
vm.save = function() {
vm.saving = true; // let the view know we're working
MyService.save(vm.ngModel)
.then(function() {
vm.saving = false;
});
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment