我創建了以下表單作爲一個角度指令並嘗試從父控制器訪問名字。 請幫助我或指導我如何從MainCtrl內訪問指令表單字段。如何訪問AngularJS指令表單字段到父控制器中
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');
}
};
}]);