I created following form as a angular directive and try to access the firstname from parent controller. Please help me or guide me how to access directive form fields from inside MainCtrl.
HTML
<pre>
{{filter-frm| json}}
</pre>
<div ng-controller="MainCtrl">
<userform></userform>
</div>
JS
.controller('MainCtrl', ['$scope', function($scope){
console.log($scope.filterForm.firstname) //How to get this ?
};
.directive('userform', [function () {
return {
restrict: 'E',
scope: { formCtrl: '=' }
template: '<div>'
+ '<form id="filterForm" ng-submit="login()">'
+ '<input name="firstname" ng-model="user.firstName">'
+ '</form> '
+ '</div>',
link: function (scope, element, iAttrs) {
var form = element.find('form');
scope.formCtrl = form.controller('form');
}
};
}]);