I have a directive that includes switching with a form in it. I want to access the form from a directive, but it is undefined.
How do I access the transplantation area?
I'm new to angular, so maybe I'm trying to make it no better?
I did a simple demo to illustrate what I'm trying to do.
https://plnkr.co/edit/wzq5oFTuoAqVJMF2RUy2?p=preview
<my-directive>
<form role="form" name="myForm" ng-submit="submit()">
<input type="text" id="myInput" ng-model="myInput" />
<input type="submit" value="Submit" />
</form>
</my-directive>
var myApp = angular.module('myApp', []);
myApp.controller('myController', function myController($scope){
});
myApp.directive('myDirective', function(){
return {
template: '<div ng-transclude></div>',
restrict: 'E',
transclude: true,
replace: true,
link: function (scope, element, attrs) {
scope.submit = function(){
debugger;
var myForm = scope.myForm;
}
}
}
});
source
share