我刚刚升级到Angular 2 RC 5了一个我无法弄清楚的原因,我无法发出任何http请求(即请求永远不会出现/不会显示在浏览器日志中).
这是直到今天升级的代码.
console.log("Let's call github");
let url = 'https://raw.githubusercontent.com/angular/angular/master/LICENSE';
return this.get(url).do(d=>console.log('success'));
Run Code Online (Sandbox Code Playgroud)
当我的组件调用包含此代码的函数时,Let's call github会输出,但是不会发出请求.我确信这个Observable和Http来自@angular/http正确导入,因为今天早上同样的代码工作.我的第一个想法是我错过了HttpModule,但我已经确认我将它导入我的主要版本AppModule
事实上,如果我注释掉HttpModule导入,我看不出任何区别.错误是一样的,如下:
Exception: TypeError: this._body is null
Run Code Online (Sandbox Code Playgroud)
我不明白,应该如何在angular2中以模型驱动的形式处理复选框组.
该模型有一个languages我实例化的属性,如下所示:
this.model = {
languages: []
};
Run Code Online (Sandbox Code Playgroud)
使用FormBuilder创建的形式:
this.modelForm = this.formBuilder.group({
'languages': [model.languages, Validators.required],
});
Run Code Online (Sandbox Code Playgroud)
和模板:
<div *ngFor="let language of translateService.get('languages') | async | key_value">
<input type="checkbox" name="languages[]" formControlName="languages" value="{{ language.key }}" id="language_{{ language.key }}">
<label attr.for="language_{{ language.key }}">{{ language.value }}</label>
</div>
Run Code Online (Sandbox Code Playgroud)
在div需要对造型的目的(定制复选框),key_value使按键和循环使用的语言,明显的价值.
第一个问题来自验证.如果检查并取消选中一个复选框(并且未选中其他复选框),则输入仍然有效 - 不知何故很奇怪.
第二个问题伴随着价值,即true如果检查两种或更多种语言,则false另外.
然后有第三个问题,其初始值languages只是一个空数组,但会导致所有复选框最初被检查(如果初始值设置为a string,则不会发生),尽管我无法发现任何checked属性DOM.
我正在使用最新的离子beta(2.0.0-beta.10),它使用角度/核心版本2.0.0-rc.4和角度/形式版本0.2.0.
那么,有没有关于如何使用复选框组的指南?有什么建议或想法吗?
我有一个表单,它根据下拉列表中的某些值更改其验证。如果选择 A 大学,那么最低百分比要求为 60,如果选择 B 大学,则最低百分比会下降到 55。尽管我已经找到了一种方法来获取模板中的最小错误,这样我就不必费力了在我的模板中编写百分比值。虽然我不确定这是否是正确的方法。
<div formGroupName="marks">
<div class="form-group">
<label for="email" class="col-lg-3 control-label">Semester 1</label>
<div class="col-lg-3">
<input autocomplete="off"
#sem1
type="text"
min="0"
max="99"
maxlength="1"
maxlength="2"
class="form-control"
id="email"
placeholder="Sem 1 (%)"
(keypress)="onlyNumberKey($event)"
formControlName="sem1">
<span *ngIf="registrationForm.controls['marks'].controls['sem1'].hasError('required') &&
registrationForm.controls['marks'].controls['sem1'].touched"
class="text-danger">
Sem 1 percentage required
</span>
<span *ngIf="registrationForm.controls['marks'].controls['sem1'].hasError('min') ||
registrationForm.controls['marks'].controls['sem1'].hasError('max') ||
registrationForm.controls['marks'].controls['sem1'].hasError('minlength')||
registrationForm.controls['marks'].controls['sem1'].hasError('maxlength') &&
registrationForm.controls['marks'].controls['sem1'].touched"
class="text-danger">
Percenatge must be {{ registrationForm.get('marks.sem1')._errors.min.min }} and above.
</span>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
成分
registrationForm = new FormGroup({
college: new FormControl('', [
Validators.required, dropDrownValidator
]),
marks: new FormGroup({ …Run Code Online (Sandbox Code Playgroud) 我正在使用@michaelbromley的dir-pagination指令.我想获得当前指令页面上的所有记录.有没有办法做到这一点?
这是链接:dir-pagination,所以我需要records从100到96 的5的集合.有没有快速的方法来做到这一点?
我尝试了几件但没有工作.
我正在做一个项目,我遇到了属性问题download:我发现Safari浏览器不支持它(根据文档).
这是一个片段:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<a href="http://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon@2.png?v=73d79a89bded&a" download>Press to Download</a>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
我搜索的方式用纯做到这一点Javascript还是Angular,但我没有找到什么.如果有人有解决方案会很棒.
请考虑以下数据:
food = {
id: 1,
name: 'Pizza',
price: 16
};
orders = [
{ food_id: 2, table_id: 5 },
{ food_id: 2, table_id: 5 },
{ food_id: 1, table_id: 5 },
{ food_id: 3, table_id: 5 },
{ food_id: 1, table_id: 5 }
];
Run Code Online (Sandbox Code Playgroud)
我想从orders数组匹配中删除单个项目food_id.这是我试过的:
removeFoodOrder(food: Food): void {
for (let order of this.orders) {
let match = this.orders.filter((order) => order.food_id == food.id);
match ? this.orders.splice(this.orders.indexOf(order), 1) : null;
break;
}
console.log(this.orders);
}
Run Code Online (Sandbox Code Playgroud)
如果我调用removeFoodOrder(food) …
我正在开发一个网络应用程序,我需要缓存图像,以便在用户关闭并再次打开网站时不需要时间加载。再次打开网站时,应该从缓存中加载图像,而不是再次重新加载。
这可以用 Angular 来实现吗?
我在网上搜索了很多,但还没有找到合适的解决方案。
我的嵌套表单目前以这种方式格式化:
ngOnInit() {
this.user = this.fb.group({
name: ['', [Validators.required, Validators.minLength(2)]],
quest1: ['', Validators.required],
account: this.fb.group({
email: ['', Validators.required],
confirm: ['', Validators.required]
}),
questions: this.fb.group({
quest2: ['', Validators.required],
}),
});
}
Run Code Online (Sandbox Code Playgroud)
我通常会设置这样的值:
this.user.controls['quest1'].setValue('false');
但是因为formGroups是嵌套的,所以我不确定如何设置嵌套值.
如何设置"quest2"的值?在嵌套的formGroup中设置表单控件值的正确语法是什么?
编辑:我正在使用这种方式
this.user.controls['quest1'].setValue('false');
forms typescript angular2-forms angular angular-reactive-forms
我正在使用我的Angular 4项目的默认i18n进程,所以我ng-i18n用来生成.xlf没有问题.
但是根据我的打字稿代码,我还有一些文本需要翻译并通过id检索当前语言.
在Angular 4中我找不到任何方法.我错过了什么吗?如果那件事,我正在使用AOT.
如果服务器从Web服务发回一些消息/错误代码,如何使用Angular转换它们,也会出现此问题
我有一个json如下:
[{
"_id": "58a58ea23744cd46918914ef",
"entityId": "ce7200c1-3430-47ce-ab81-7d0622cb8cae",
"name": "Portugal",
"description": "Portugal",
"type": "country",
"category": "common",
"subcategory": "common",
"parent": {
"_id": "58a8486ca4890027348a8966"
},
"image": {
"_id": "58a8486ca4890027348a8965"
},
"metadata": {
"primary": "pt",
"taxRate": 20,
"exchangeRate": 0.7,
"language": "PT",
"currency": "EUR",
"_id": "58a8486ca4890027348a8964"
}
}, {
"_id": "58a58ea23744cd46918914f1",
"entityId": "815b9e90-e36f-4488-ad50-6a259b6d034d",
"name": "Qatar",
"description": "Qatar",
"type": "country",
"category": "common",
"subcategory": "common",
"parent": {
"_id": "58a8486ca4890027348a8969"
},
"image": {
"_id": "58a8486ca4890027348a8968"
},
"metadata": {
"primary": "qa",
"taxRate": 20,
"exchangeRate": 0.7,
"language": "RO",
"currency": "RO",
"_id": …Run Code Online (Sandbox Code Playgroud) angular ×8
typescript ×3
angularjs ×2
javascript ×2
angular2-aot ×1
caching ×1
ecmascript-6 ×1
forms ×1
html5 ×1
ionic2 ×1
pagination ×1
pipe ×1