- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我想将我的 ngForm 和 ngModelGroup 从父组件转移到子组件,并在子组件中使用表单验证功能。
父组件.html:
<md-step [stepControl]="createIntegrationPartnerRequestGroup">
<form #createIntegrationPartnerRequestForm="ngForm">
<div ngModelGroup="createIntegrationPartnerRequestGroup" #createIntegrationPartnerRequestGroup="ngModelGroup">
<div class="row p-row-padding">
<div class="col-xs-12">
<ng-template mdStepLabel>
{{'INTEGRATION_PARTNER_REQUEST' | translate}}
</ng-template>
</div>
</div>
<integration-partner-request [form]="createIntegrationPartnerRequestForm"
[model]="createIntegrationPartnerRequestGroup"></integration-partner-request>
</div>
</form>
</md-step>
子 Component.html(摘录):
<div class="row p-row-padding">
<div class="col-xs-6">
<md-input-container class="p-full-width">
<input mdInput
ngModel name="name"
#name="ngModel"
required
(change)="showForm()"
placeholder="{{'WELCOME_WIZARD.PARTNER_NAME' | translate}}">
<md-error *ngIf="name.touched && name.invalid">
<span *ngIf="name.errors.required">
{{'WELCOME_WIZARD.FIELD_REQUIRED' | translate}}
</span>
<span *ngIf="name.errors.pattern">
{{'WELCOME_WIZARD.INVALID_FIELD_FORMAT' | translate}}
</span>
</md-error>
</md-input-container>
</div>
<div class="col-xs-6">
<md-input-container class="p-full-width">
<input mdInput
ngModel name="status"
#status="ngModel"
placeholder="{{'WELCOME_WIZARD.PARTNER_STATUS' | translate}}">
<md-error *ngIf="status.touched && status.invalid">
<span *ngIf="status.errors.required">
{{'WELCOME_WIZARD.FIELD_REQUIRED' | translate}}
</span>
<span *ngIf="status.errors.pattern">
{{'WELCOME_WIZARD.INVALID_FIELD_FORMAT' | translate}}
</span>
</md-error>
</md-input-container>
</div>
</div>
子组件.ts:
export class ChildComponent implements OnInit {
@Input() public form: FormGroup;
@Input() public model: NgModelGroup;
@Input() public type: string;
public formResult;
public modelResult;
constructor() {
}
ngOnInit() {
this.formResult = this.form;
this.modelResult = this.model;
}
public showForm() {
console.log(this.formResult);
console.log(this.modelResult);
}
}
子组件中还有一个按钮,它应该只在必填字段不为空时才起作用,但事实并非如此,因为 modelResult
没有任何字段值... :
<button
class="p-full-width"
md-raised-button
[disabled]="formResult.invalid"
mdStepperNext>
{{'WELCOME_WIZARD.NEXT' | translate}}
</button>
我做错了什么?
最佳答案
你所做的一切都是正确的——除了 Angular 2/4 不支持它。如果您查看 NgModel 的源代码你会看到它包含这样的定义:
constructor(@Optional() @Host() parent: ControlContainer,
...)
这意味着 DI 容器只会在第一个 @Host() 之前寻找这种依赖关系——你猜怎么着? - 你的子组件。这意味着 NgModel 不会找到您的表单,也不会在其中注册自己。每个 @Component() 都是一个宿主,所以没有办法让它像这样工作。
因此,您的选择在这里真的很有限:将所有表单部分集中在一个组件中或构建您自己的 NgModel 实现。
正如@yurzui 指出的(谢谢!)有一个解决方案:click .我自己没有尝试过,但我不明白为什么它不起作用 - 而且它非常简单和优雅。
关于 Angular (4) : transfer ngForm & ngModelGroup from parent to child and use form validation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46776774/
I made an example , 我直接从 jQuery website 复制了它然而,它不会转移.. HTML: BLAHHHH
所以我对名字有一些误解STATE TRANSFER在 REPRESENTATIONAL STATE TRANSFER. 是 state transfer意味着传输当前时间实例中服务器中存在的资源的表示
我的代码将文件从远程服务器下载到我们的服务器。 通常,一个文件最多需要一分钟左右的时间才能完成下载。但有时下载时间会超过 5 分钟。 如果当前下载时间超过 5 分钟,是否可以重新开始下载? Tamir
Representational State Transfer中的State Transfer是指什么? 找到了一些关于这个的解释(例如 here )但我还是不明白。例如文章中说 The repres
在阅读 C# 时,我遇到了“数据传输类型”和“数据传输对象”这两个术语。这显示在匿名类型周围,其中动态创建类型以保存结果,例如来自 LINQ。这两个术语指的是同一件事吗? 谢谢, 斯科特 最佳答案 我
以下代码: public string add_button_tooltip_markup { get { return add_button.get_tooltip_markup (); }
您可以在下面看到外部测试人员的测试已关闭: 内部测试相同: 但是当我转移应用程序时,不满足其中一个条件: 为什么? 最佳答案 我遇到了完全相同的问题,通过如上所述从 TestFlight 中删除所有
我对 Java 和 REST/REST 很陌生。我正在尝试创建一个设置了“Transfer-Encoding: chunked”的 POST 请求(通过 header ),但出现异常“org.apac
我是 mysql 新手,想知道我在代码中会怎么说。如果 Narrive = "transfer"则将 AccountID 更改为 2001 请有人给我一步一步的说明,并请解释一下我会将这段代码放在哪里
我有一个对象是数据库查询的结果,看起来像这样(var_dump 输出): object(stdClass)#17 (6) { ["id"]=> string(1) "1" ["title"
使用方法 Server.Transfer("default.aspx")以获得更好的在网站内导航的性能。当我使用它时,它不会更改地址栏中的 url。如何通过 server.transfer 获取新 u
我正在使用 lftp 将文件从本地传输到仅允许 SFTP 访问的远程服务器。 我使用以下语法来传输文件: lftp -c "open -u $UN,$Pass sftp://$Server ; mir
使用我编写的FTP客户端,有时上传完成后,有时会从FileZilla服务器收到226 Transfer OK消息,有时我什么也收不到。并不是在收到226 Transfer OK之前客户端已断开连接,因
我的 Chrome 应用程序和一个简单的设备之间没有发生任何类型的传输,只是等待数据进入其 uart rx 线路。设备接口(interface)的端点类型为bulk,尽管我已经尝试了所有可用的传输类型
我正在通过 SFTP 和 FileZilla 传输一个非常大的 (35GB) 文件。 现在传输已完成59.7%,但我不断收到此错误,并且几个小时内该数字都没有更改。 Error: File t
经过大量研究,我仍然没有答案。 我使用 WebForm 应用程序 VS 2013。 我的代码相当简单: Server.Transfer("~/Success.aspx",true); 此后,执行 Su
抱歉,标题令人困惑;然而,描述和插图应该可以解决这个问题。 本质上,我有表 A 表示表 B 的行之间“金额”转移的实例。 我希望加入 A 和 B 以便我可以显示转帐的详细信息: ===========
我正在使用 iOS 版 Plaid API 编写一个程序,该程序在身份验证后访问银行帐户并显示交易数据。 我需要知道是否可以在帐户之间转移资金(支票到储蓄)以及如何转移。 我知道 acorns 使用相
我需要通过同一网络在不同计算机之间复制/传输一些文件。经过一些阅读和搜索后,我认为尝试 Java 的 jsch 可能是一个不错的选择。令人痛苦的事实是,可能没有针对 jsch 的好的文档。但据我所知,
我正在使用 XMLHttpRequest 读取 json 文件,发现“通过网络传输”明显大于资源大小。 xmlhttp.open("GET", "resources.json", true); 而其他
我是一名优秀的程序员,十分优秀!