Created
May 18, 2015 18:50
-
-
Save icfantv/1b6a3eb0a98c6bd9ebc0 to your computer and use it in GitHub Desktop.
Isolate Form Directive
This file contains 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 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