Angularjs directive 查找用于在隔离范围内提交表单数据的变通方法
在我的应用程序中,有几个表单嵌套在tab元素中。以下是选项卡和窗格指令代码:Angularjs directive 查找用于在隔离范围内提交表单数据的变通方法,angularjs-directive,angularjs-scope,Angularjs Directive,Angularjs Scope,在我的应用程序中,有几个表单嵌套在tab元素中。以下是选项卡和窗格指令代码: .directive('tabs', function() { return { restrict: 'E', transclude: true, scope: {}, controller: function($scope) { var panes = $scope.panes = []; $scope.select = function(pane) { angular
.directive('tabs', function() {
return {
restrict: 'E',
transclude: true,
scope: {},
controller: function($scope) {
var panes = $scope.panes = [];
$scope.select = function(pane) {
angular.forEach(panes, function(pane) {
pane.selected = false;
});
pane.selected = true;
};
this.addPane = function(pane) {
if (panes.length === 0) {
$scope.select(pane);
}
panes.push(pane);
};
},
templateUrl: 'partials/tabs.ejs'
}
.directive('pane', function() {
return {
require: '^tabs',
restrict: 'E',
transclude: true,
scope: {
title: '@'
},
link: function(scope, element, attrs, tabsCtrl) {
tabsCtrl.addPane(scope);
},
templateUrl: 'partials/pane.ejs'
};
});
以下是控制器代码:
.controller('MainCtrl', ['$scope', 'courses', function($scope, courses) {
$scope.courses = courses.courses;
$scope.addCourse = function() {
if (!$scope.title || $scope.title === '') return;
courses.create({
title: $scope.title,
description: $scope.description,
professor: $scope.professor
});
$scope.title = '';
$scope.description = '';
$scope.professor = '';
};
}])
最后,这里是相关的HTML:
<div ng-controller="MainCtrl">
<script type="text/ng-template" id="/home.html">
<tabs class="container">
<pane title="All Courses"
<div class="container">
<form ng-submit="addCourse()">
...
你如何提交表格?你有按钮元素吗?按钮类型是否=提交?是,它通过按钮类型=提交元素。最后,我通过使用引导和jQuery而不是Angular中的转置作用域来更改静态选项卡,从而解决了这个问题。