我创建了一个简单的示例来演示我面临的一个奇怪问题。
Stackblitz- https: //stackblitz.com/edit/angular-change-detection-form-group
我有三个组成部分,它们是:
1-应用程序组件
import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
import { FormGroup, FormControl } from '@angular/forms';
@Component({
selector: 'my-app',
template: `<hello [form]="form"></hello>
<hr />
<button (click)="changeFormValue()">Change Form Value</button>`,
styleUrls: ['./app.component.css'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class AppComponent implements OnInit {
name = 'Angular';
form: FormGroup;
ngOnInit() {
this.form = new FormGroup({
name: new FormControl('ABC'),
age: new FormControl('24')
});
}
changeFormValue() {
this.form.setValue({
name: 'XYZ',
age: 35
})
}
}
Run Code Online (Sandbox Code Playgroud)
2-Hello组件
import { Component, Input, OnChanges, ChangeDetectionStrategy …Run Code Online (Sandbox Code Playgroud) 我有一个动态创建文本框的按钮,还有另一个按钮'清除'.
如果任何文本字段中没有文本,则禁用清除按钮,否则将启用它.它适用于加载dom时创建的文本框,但对于动态创建的文本框,它不起作用.
这是HTML
<input type="button" value="Click Me" class="a" />
<input type="button" value="Clear" class="a" id="clearBasicSearch" />
<div id="basicSearchFields">
<input type="text" />
</div>
Run Code Online (Sandbox Code Playgroud)
使用Javascript
$(".a").click(function () {
$("#basicSearchFields").append("<input type='text' class='b' />");
});
/*$(".b").live("keyup", function () {
//alert('you pressed ' + $(this).val());
$(this).val($(this).val().toUpperCase());
});*/
var toValidate = $("#basicSearchFields input[type='text']");
$("#clearBasicSearch").removeClass('hidden').removeClass('button').attr('disabled', true);
toValidate.live('keyup', function () {
console.log("hi");
var valid = false; //default is false
toValidate.each(function () {
if ($(this).val().length > 0) {
valid = true; //non-empty element found
return false; //break
}
}); …Run Code Online (Sandbox Code Playgroud) 我想检查 08/2014 是否大于 02/2014..
我怎样才能在 Javascript 中做到这一点?有人可以帮我吗...
目前我只检查未来一年。这是代码片段。
this.isDateGreaterThanCurrent=function(b){
return parseInt(b)>parseInt(new Date().getFullYear());
};
Run Code Online (Sandbox Code Playgroud) 我正在使用 python xlrd 模块来解析 Excel 文件。这是excel文件的样子:
Title A B C
attribute 1 1 2 3
attribute 2 4 5 6
attribute 3 7 8 9
Run Code Online (Sandbox Code Playgroud)
我想要以下格式的输出:
[
{
"name": "A",
"attribute1": {
"value": 1
},
"attribute2": {
"value": 4
},
"attribute3": {
"value": 7
}
},
{
"name": "B",
"attribute1": {
"value": 2
},
"attribute2": {
"value": 5
},
"attribute3": {
"value": 8
}
},
{
"name": "C",
"attribute1": {
"value": 3
},
"attribute2": {
"value": 6
},
"attribute3": { …Run Code Online (Sandbox Code Playgroud) 我想以角度动态加载子组件。父组件将根据某些条件加载子组件。
我们是否可以在父组件打字稿文件中定义子组件名称,并在 HTML 中使用字符串插值来加载组件?
例如在父组件打字稿中:
componentName = someCondition ? 'component1' : 'component2';
Run Code Online (Sandbox Code Playgroud)
在 HTML 中
<app-{{componentName}}></app-{{componentName}}
Run Code Online (Sandbox Code Playgroud)
我尝试过这个,但它不起作用。对此有任何帮助将不胜感激!