针对【Angular】---IfngModelisusedwithinaformtag,eitherthenameattributemustbesetortheform这个问题,本篇文章进行了详细的解
针对【Angular】--- If ngModel is used within a form tag, either the name attribute must be set or the form这个问题,本篇文章进行了详细的解答,同时本文还将给你拓展''statusBarFrame'' was deprecated in iOS 13.0: Use the statusBarManager property of the win...、An Errors/BindingResult argument is expected to be declared immediately after the model attribute, the @RequestBody or the @RequestPart arguments to which they apply: public com.rongrong.springboot.de、android 报错 ':app:transformClassesWithMultidexlistForDebug' 或者 transformDexArchiveWithExternalLibsDexMergerForDebug,三步搞定!、Angular5 错误: ngModel cannot be used to register form controls with a parent formGroup directive等相关知识,希望可以帮助到你。
本文目录一览:- 【Angular】--- If ngModel is used within a form tag, either the name attribute must be set or the form
- ''statusBarFrame'' was deprecated in iOS 13.0: Use the statusBarManager property of the win...
- An Errors/BindingResult argument is expected to be declared immediately after the model attribute, the @RequestBody or the @RequestPart arguments to which they apply: public com.rongrong.springboot.de
- android 报错 ':app:transformClassesWithMultidexlistForDebug' 或者 transformDexArchiveWithExternalLibsDexMergerForDebug,三步搞定!
- Angular5 错误: ngModel cannot be used to register form controls with a parent formGroup directive
【Angular】--- If ngModel is used within a form tag, either the name attribute must be set or the form
【前言】:
在最近的项目中,对angular的学习也才算是开始入门。对于angular小白的我来说,每次遇到问题都是很好的成长机会,哪怕很小,(#^.^#)。不断的在错误中成长吧。
【错误】:
ERROR Error: If ngModel is used within a form tag,either the name attribute must be set or the form control must be defined as 'standalone' in ngModelOptions. Example 1: <input [(ngModel)]="person.firstName" name="first"> Example 2: <input [(ngModel)]="person.firstName" [ngModelOptions]="{standalone: true}">
【分析】:
要能有很好的耐心看错误提示很重要,每一个错误的解决方案也往往就在错误提示中隐藏甚至是“暴露”着。O(∩_∩)O哈哈~
上面的异常信息告诉我们如果再表单标签中使用ngModel,则必须设置name属性,或者在ngModelOptions中必须将表单控件定义为“standalone”。
因为ngForm持有通过ngModel指令和name属性为各个元素创建的那些控件,并且监视他们的属性变化,包括有效性。它还有自己的valid属性,只当其中的所有控件都有效时,它才有效。
【理论】:
angular2的表单主要用到了ngForm,ngModel,ngSubmit。ngSubmit对应的函数是我们提交表单调用的函数。angular2通过ngForm将按钮的禁用/启用状态和表单的有效性关联起。
#loginForm、#username和#userpwd都是angular2中的模板引用变量;
#username和#userpwd可以监控input输入框的状态,#loginForm可以用来监控表单的状态,通过这些状态可以进行输入错误提示以及表单提交控制。
HTML控件(比如input、select等)的状态主要包括:
pristine和dirty:控件是否使用过,或者理解成是否输入过内容
invalid和valid:控件输入是否有效
touched和untouched:控件是否已经被访问过。
【实战】:
<div> <form role="form"#validationForm1="ngForm"> <div> <div> <label>姓名:</label> <label> <input type="text" id="familyMemName"[(ngModel)]="homeInfo.familyMemName" name="familyMemName" ngModel #familyMemName="ngModel" required> </label> </div> <div> <label>关系:</label> <label> <select[(ngModel)]="homeInfo.relationshipId" name="relationshipId" required> <option *ngFor="let option of relationoptions" [value]="option.id">{{option.dictName}}</option> </select> </label> </div> </div> …… </div> </form> </div> <div> <!-- [disabled]="!addform.form.valid" --> <button type="button"[disabled]="!validationForm1.form.valid" (click)="add(addModal)"> 添加 </button> <button type="button"(click)="close(addModal)"> 取消 </button> </div>
【总结】:
validationForm1.form.valid用来判断form表单中的控件是否全部有效。在ng2表单中使用ngModel必须带name属性或者使用[ngModelOptions]=”{standalone: true}”。否则会报上面的错误。
''statusBarFrame'' was deprecated in iOS 13.0: Use the statusBarManager property of the win...
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公众号:山青咏芝(let_us_code)
➤博主域名:https://www.zengqiang.org
➤GitHub 地址:https://github.com/strengthen/LeetCode
➤原文地址:https://www.cnblogs.com/strengthen/p/12109327.html
➤如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章。
➤原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
由于未捕获的异常 “NSInternalInconsistencyException” 而终止应用程序,原因:“在 UIApplication 上名为 - statusBar 或 - statusBarWindow 的应用程序:必须更改此代码,因为不再有状态栏或状态栏窗口。而是在窗口场景上使用 statusBarManager 对象。”
但是目前尚不清楚应如何使用它来更改颜色,因为keyWindow?.windowScene?.statusBarManager
它似乎不包含与之相关的任何内容。
1 //MARK: 扩展UIApplication
2 extension UIApplication {
3 var statusBarUIView: UIView? {
4
5 if #available(iOS 13.0, *) {
6 let tag = 3848245
7
8 let keyWindow = UIApplication.shared.connectedScenes
9 .map({$0 as? UIWindowScene})
10 .compactMap({$0})
11 .first?.windows.first
12
13 if let statusBar = keyWindow?.viewWithTag(tag) {
14 return statusBar
15 } else {
16 let height = keyWindow?.windowScene?.statusBarManager?.statusBarFrame ?? .zero
17 let statusBarView = UIView(frame: height)
18 statusBarView.tag = tag
19 statusBarView.layer.zPosition = 999999
20
21 keyWindow?.addSubview(statusBarView)
22 return statusBarView
23 }
24
25 } else {
26
27 if responds(to: Selector(("statusBar"))) {
28 return value(forKey: "statusBar") as? UIView
29 }
30 }
31 return nil
32 }
An Errors/BindingResult argument is expected to be declared immediately after the model attribute, the @RequestBody or the @RequestPart arguments to which they apply: public com.rongrong.springboot.de
报错信息:
An Errors/BindingResult argument is expected to be declared immediately after the model attribute,the @RequestBody or the @RequestPart arguments to which they apply: public com.rongrong.springboot.demo.domain.Student com.rongrong.springboot.demo.controller.StudentController.studentAddByParam(java.lang.String,java.lang.Integer,java.lang.String,org.springframework.validation.BindingResult)
处理方法:BindingResult 要跟在实体类之后,
如:
@Valid Student student,BindingResult bindingResult
参考链接:https://blog.csdn.net/qq_28643817/article/details/98492052
android 报错 ':app:transformClassesWithMultidexlistForDebug' 或者 transformDexArchiveWithExternalLibsDexMergerForDebug,三步搞定!
问题分析: 重复依赖所导致的。
解决问题步骤:
1. 查看 android > app > build.gradle 下有没有这样一行代码 ,没有的话添加试一下。
multiDexEnabled true
2.查看 android > app > build.gradle 中 dependencies 下是否有重复依赖,有则删除,项目即可运行成功。
(如果不清楚哪个依赖是重复的,可以试一下 在命令行 gradle installdebug –stacktrace把堆栈日志打出来,应该可以打印出来重复依赖是哪一个,这个我是在网上看的,未测试)
3. 如果还是不行 ,把 android > app > build.gradle 中 dependencies 的引入方式 compile 改为 implementation ,如图:
OK,试过这三步绝对能行了,是不是很开心?
Angular5 错误: ngModel cannot be used to register form controls with a parent formGroup directive
在创建一个表单时,出现了这样的错误:
原因是,在最外层的form中使用了 formGroup 指令,但在下面的某个input 元素中,使用了ngModel 指令,但没有加入formControl 指令或 formControlName 属性。
也就是说,如果form中使用了formGroup,那么form中包含的所有input 元素都需要定义一个 formControl,如果不定义,就会报错。
1 <form [formGroup]="form">
2 <mat-form-field>
3 <input matInput placeholder="IP(SNMP)" [formControl]="snmpIpCtrl" required>
4 <mat-error *ngIf="snmpIpCtrl.hasError(''required'')">IP(SNMP)不能为空</mat-error>
5 <mat-error *ngIf="snmpIpCtrl.hasError(''pattern'')">请输入有效的IP地址</mat-error>
6 </mat-form-field>
7
8 <div>
9 <p>是否支持Netconf</p>
10 <mat-radio-group [(ngModel)]="netconfFlag">
11 <mat-radio-button value="0" color="primary">支持</mat-radio-button>
12 <mat-radio-button value="1" color="primary">不支持</mat-radio-button>
13 </mat-radio-group>
14 </div>
15 </form>
解决方法1:
在input元素中添加 formControl 指令或 formControlName 属性
1 <div>
2 <p>是否支持Netconf</p>
3 <mat-radio-group [(ngModel)]="netconfFlag" [formControl]="netconfFlagCtrl">
4 <mat-radio-button value="0" color="primary">支持</mat-radio-button>
5 <mat-radio-button value="1" color="primary">不支持</mat-radio-button>
6 </mat-radio-group>
7 </div>
并在相应的component.ts 中定义用于验证的FormControl。
解决方法2:
不添加formControl 指令或 formControlName 属性, 而添加 ngModelOptions 指令
注意 ngModelOptions 必须和 ngModel 一起用!
1 <div>
2 <p>是否支持Netconf</p>
3 <mat-radio-group [(ngModel)]="netconfFlag" [ngModelOptions]="{standalone: true}">
4 <mat-radio-button value="0" color="primary">支持</mat-radio-button>
5 <mat-radio-button value="1" color="primary">不支持</mat-radio-button>
6 </mat-radio-group>
7 </div>
今天的关于【Angular】--- If ngModel is used within a form tag, either the name attribute must be set or the form的分享已经结束,谢谢您的关注,如果想了解更多关于''statusBarFrame'' was deprecated in iOS 13.0: Use the statusBarManager property of the win...、An Errors/BindingResult argument is expected to be declared immediately after the model attribute, the @RequestBody or the @RequestPart arguments to which they apply: public com.rongrong.springboot.de、android 报错 ':app:transformClassesWithMultidexlistForDebug' 或者 transformDexArchiveWithExternalLibsDexMergerForDebug,三步搞定!、Angular5 错误: ngModel cannot be used to register form controls with a parent formGroup directive的相关知识,请在本站进行查询。
本文标签: