Skip to content

Instantly share code, notes, and snippets.

@icfantv
Created May 18, 2015 18:50
Show Gist options
  • Save icfantv/1b6a3eb0a98c6bd9ebc0 to your computer and use it in GitHub Desktop.
Save icfantv/1b6a3eb0a98c6bd9ebc0 to your computer and use it in GitHub Desktop.
Isolate Form Directive
function IsolateFormDirective() {
return {
restrict: 'A',
require: '?form',
link: function link(scope, $element, attrs, formController) {
if (!formController) {
return;
}
// Remove this form from parent controller
var parentFormController = $element.parent().controller('form');
parentFormController.$removeControl(formController);
// Replace form controller with a 'null-controller'
var isolateFormCtrl = {
$addControl: angular.noop,
$removeControl: angular.noop,
$setValidity: angular.noop,
$setDirty: angular.noop,
$setPristine: angular.noop
};
angular.extend(formController, isolateFormCtrl);
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment