Skip to content

Instantly share code, notes, and snippets.

@vance
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vance/db40c407fdb81ba762ca to your computer and use it in GitHub Desktop.
Save vance/db40c407fdb81ba762ca to your computer and use it in GitHub Desktop.
Directive that watches scope for data changes
app.directive('alertSuccess', function() {
return {
require: 'ngModel',
link: function(scope, ele, attrs, ngModelController) {
scope.$watch(attrs.ngModel, function(value) {
//broadcast to your GlobalNotificationController to bring in a dialog etc.
scope.$emit('dataUpdated', value)
});
}
};
});
//then in your html
<form name="newWidgetForm" novalidate alert-success>
<input name="name" type="text" ng-model="newWidgetCtrl.widget.name" ensure-expression="newWidgetCtrl.widget.name.length >= 5" required />
... ... ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment