我的 Angular 4 应用程序使用 Spring Data REST API HATEOAS 服务器,我使用的是 HttpClient,我看到它返回 Object 而不是any像 http。我读到这个问题:为什么 angular 4.3 中的 httpclient 返回 Object 而不是 any?
我明白了。我有很多像这样的字段的复杂 json:
{
"_embedded": {
"customers": [
{
"sid": "c44fdb6f-9b7c-4f75-8d4c-7542f54037b7",
"createdDate": "2017-08-01T13:06:23Z",
"lastModifiedDate": "2017-08-01T13:06:23Z",
"lastModifiedBy": "admin",
"name": "Customer 1",
"username": "customer1",
"address": "Via xxxxx",
"city": "Adria",
"landlinePhone": "+39042000000",
"mobilePhone": null,
"email": "email@test.it",
"fax": null,
"vatNumber": "IT01000020295",
"taxCode": null,
"iban": null,
"swift": null,
"enableEcommerce": true,
"balance": 0,
"enabled": true,
"new": false,
"_links": {
"self": {
"href": …Run Code Online (Sandbox Code Playgroud) 我必须将一些参数字符串化以将其放入http补丁请求中,我的方法是这样的
let param = JSON.stringify({
code : this.code,
name : this.name,
fieldName: this.data
});
Run Code Online (Sandbox Code Playgroud)
在那种情况下,我有一个这样的参数:
代码:3,名称:'asdf',fieldName:'col'
但我希望fieldName ond的值不是单词fieldName ...是否有方法来扩展或评估此参数名称?
嗨我想在GET请求中发送参数,但我的搜索参数仍为空,这是我的代码:
private jwt2() {
let currentUser = JSON.parse(localStorage.getItem('currentUser'));
console.log('current.token ' + currentUser.token);
let params: URLSearchParams = new URLSearchParams(); //PARAMS
params.set('pageSize', '6'); //pageSize
let headers = new Headers({ 'Authorization': currentUser });
console.log("params: " + params); //here I can see correct params
return new RequestOptions({ headers: headers, search: params });
// }
}
Run Code Online (Sandbox Code Playgroud)
我可以在chrome中看到正确的标题但不是搜索参数:
search
URLSearchParams
paramsMap
Map(0)
size(0)
__proto__
Map
[[Entries]]
Array(0)
length(0)
Run Code Online (Sandbox Code Playgroud)
如果我没有设置params并手动将param写入这样的搜索选项:
return new RequestOptions({ headers: headers, search: 'pageSize=6' });
它可以工作
在我的angular 4项目中,我正在使用带有Sweetalert 2的主题,我想在用户单击确认按钮时调用我的方法,但是看来我无法在then函数中调用任何方法
swal({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then(function () {
// I want to call my method here but I can't do this.myMethod()
})
Run Code Online (Sandbox Code Playgroud)
我知道这不是棱角分明的甜言蜜语,但有可能使其无需更改就能正常工作吗?
我必须将输入集中在加载模式上,但是如果我使用html5属性,autofocus它似乎无法正常工作。有可能使其工作吗?
<div class="col-md-6">
<div class="form-group label-floating">
<label class="control-label">
{{'ticketbundle.busroutedetail.dialog.labels.buslinename'
| translate }}<span class="star">*</span>
</label><input autofocus class="form-control" id="name" required
[(ngModel)]="busRouteDetail.name" name="name" #busRouteDetailname>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我正在使用角材2
在我的angular 4项目中,我必须在输入字段和MatSelect中设置一些值而没有任何绑定。
这是HTML
<div class="row search-component">
<div class="col-md-5 no-padding-right">
<mat-form-field>
<mat-select placeholder="searchfor" id="selectedFilter" name="propertyList" #selectedFilter>
<mat-option *ngFor="let property of propertyList" [value]="property">
{{property.label}} </mat-option>
</mat-select>
</mat-form-field>
</div>
<div class="col-md-7 no-padding-left">
<mat-form-field>
<input matInput placeholder="search" id="searchfield" name="searchfield" #selectedValue>
<mat-icon class="pointer" matSuffix>search</mat-icon>
</mat-form-field>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
当我单击按钮时,我必须在输入字段中设置Mat-option和一个值。
这是必须设置值的方法:
setField(chipSelected: Filter) {
this.filter = chipSelected;
document.getElementById('searchfield').focus();
document.getElementById('searchfield').value = 'somevalue'; <-- I can't use this instruction
}
Run Code Online (Sandbox Code Playgroud)
我无法获得价值,为什么?而我该如何访问呢?
我已经习惯于ng build -prod -aot -vc -cc -dop --buildOptimize减少构建的应用程序的大小。现在这是我的情况:
是否可以减少(或拆分)这些更大的块?有什么可以帮助我检查这些模块内部的东西吗?
Ps 我已经使用webpack-analyzer来检查情况,但它无法深入这些文件。
在我的 Angular 6 应用程序中,我有一个像这样的数组:
0:"SINGLE_VISION"
1:"PROGRESSIVE"
2:"BIFOCAL"
3:"DEGRESSIVE"
4:"FILTER"
Run Code Online (Sandbox Code Playgroud)
它显示在带有翻译管道(ngx-translate)的垫选择中。
<mat-select placeholder="placeholder" formControlName="type">
{{ type | translate}} </mat-option>
</mat-select>
Run Code Online (Sandbox Code Playgroud)
现在数组按原始值排序,但我想按翻译后的值排序(并维护数组内的原始值)。
因此,我的数组保持原样,但如果我打开垫选择,我会看到按正确顺序排列的翻译。
有聪明的方法可以做到这一点吗?