- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图在我的指令中要求与 ngRepeat 的每次迭代关联的 ngForm。我试过使用 require: 'form' 但它返回时未定义,也尝试过 '^form',但它在 ngRepeat 之外给出了 mainForm。有没有像 require: 'ngForm' 这样的特殊方法,它会在我的表单 View 指令的第一个元素上为我提供 ngForm 的 Controller ?
表单 View 指令之外的父指令模板
... // some other markup
<form name="mainForm">
... // some other markup
// Vertically stacked tabs directive
// Creates left/right cols, left=stacked tabs, right=form associated content using transclude
<pills>
// Pill pane content with title attribute passed up to pills during compile for stacked tabs
<pill ng-repeat="form in formData.documents"
title="{{form.name}}">
// Generated form content for each pill pane
<form-view form="form"
model="formModel"></form-view>
</pill>
</pills>
... // some other markup
</form>
表单 View 指令模板
<fieldset ng-form="form.id"> // want reference to this controller using require
<h3 ng-bind="form.name"></h3>
<div ng-repeat="field in form.mapping.fields"
... // bunch of generated fields
</div>
</fieldset>
表单 View 指令
.directive('formView', [function() {
return {
restrict: 'E',
templateUrl: '/app/components/form-view/formview.html',
scope: {
form: '=',
model: '='
},
require: ['^tabs', '^pills', '^form'], // also tried 'form', '?form', 'ngForm', 'ngform'
link: function( $scope, $element, $attrs, ctrls ) {
$scope.tabsCtrl = ctrls[0]; // got tabs
$scope.pillsCtrl = ctrls[1]; // got pills
$scope.formCtrl = ctrls[2]; // always undefined or grabs mainForm
}
};
}]);
最佳答案
你不能“要求”指令元素内的东西,只能在它上面或上面。
实现此目的的一种方法是制作您自己的 ngForm 指令,该指令需要您的 formView,然后与它对话。它将沿用现有的 ngForm。
查看 ngForm 和 ngModel 的实现以获得真实示例 - ngForm 知道其中的 ngModels 但这不是因为表单找到模型,模型让表单知道它们的存在。
关于javascript - AngularJS如何在与指令相同的级别要求ngForm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26568651/
在 Angular 1 (1.5) 中,表单 Controller 有一个 $setSubmitted()允许您以编程方式设置 .$submitted 的方法标记为真。 如何通过 NgForm 对象在
我是 Angular 的新手,我正在使用模板驱动的表单。当我使用 NgForm 时,它抛出错误: src/app/pages/add-booking/servicing/servicing.compo
我是 Angular 的新手,我正在使用模板驱动的表单。当我使用 NgForm 时,它抛出错误: src/app/pages/add-booking/servicing/servicing.compo
我正在尝试制作一个包含两个不同组件的表单。一位家长和一位 child 。我查看了很多教程,他们都在谈论提供服务。 不过,我在这个website上找到了一个方法.它包括在子组件中添加以下内容: view
我遇到了以下问题。我想使用 NG2 Forms。根据 Angular 2 文档,在表单上使用 ngForm 指令并在输入上使用 ngControl 指令,表单应该始终能够访问输入的有效性。 如果输入与
我有简单的形式 Is required lol 和组件作为 export class InputOverviewExample { comm
我最近一直在使用 React,并且非常喜欢它,但我错过了一些我在其他框架中习惯的东西。 ngForm 中主要的一个来自 Angular,Angular 使用它来提供非常简单的表单验证。检查表单是否有效
当我提交表单时,我有这个功能 login(form: NgForm) 如果我尝试以下操作 console.log(form.value.password); // this works perfect
我是 Angular 初学者,我正在尝试打印在控制台中选择的表单元素的值。所有其他元素都已打印,但 select 选定列表元素显示 undefined。这是我的代码category.services.
我正在尝试验证使用指令生成的动态表单输入并隔离范围。在指令之外,我有主窗体,在 ng-repeat 内部,我尝试使用 ng-form,但它从未显示错误消息。最初我在 ng-repeat 上有 ng-f
目标是当用户单击按钮转到下一页时,如果页面部分填写但无效,则阻止用户继续并显示错误指示符。 在模板驱动的表单中,我有几个容器元素使用 NgModelGroup 属性来表示表单中的“页面”。在我的组件中
我正在尝试做一个登录表单组件,但我无法读取表单数据。 当我尝试在控制台上写入用户名时,'undefined' 写入。 一切看起来都很正常,但表单数据没有到达组件。 下面是html代码:
这是父 HTML 这是子 HTML 我需要访问父组件中的子窗体状态 最佳答案 子模板: 子组件: export class Ch
login 工作组件的html代码是这样的。 Regis
我想知道是否有任何方法可以检索从表单的 NgForm.controls 对象中提取的 FormControl 的 NgModel它属于哪个,或者直接从表单中检索 NgModel。 我有一个表单,在提交
如何在组件中引用“myform”?是否可以?一定要使用 formbuilder(我尽量避免使用它)吗? Value 最佳答案 实际上还有另一种方法可以做到这一点。您可以使用
这个问题在这里已经有了答案: Angular 4.4.0-4.4.2 production build throwing "No provider for NgForm!" error (2 个答案
我在 Angular 4 上处理表单,我不知道使用 NgForm 和 FormGroup 处理错误和输入验证器有什么区别。处理表格有什么大的不同吗? 最佳答案 如果我没看错,您就会遇到模板驱动表单和响
我已经包含了 FormsModule 但它显示错误。 There is no directive with “exportAs” set to “ngForm” 我的 Login.component.
Angular 6 表单验证简单示例。通过电子邮件验证和选择框(下拉)。ngForm 带有选择框的 Angular 6 简单示例 最佳答案 使用ngForm。将其导入您的 component.modu
我是一名优秀的程序员,十分优秀!