我有一个api,返回像这样的对象/数组:
(2) [{...}, {...}] object
0: {a: '1', b: {id: '1'}}
1: {a: '2', b: {id: '2'}}
Run Code Online (Sandbox Code Playgroud)
所以它看起来像对象的数组(但是debuges说'对象').
所以在我的代码中我有:
return this.http.get(this.url).pipe(
map(datas => {
return datas.map(data => {
let object = {
a: data['a'],
b: data['b']['id'],
}
return object;
})
})
);
Run Code Online (Sandbox Code Playgroud)
但那里:
return datas.map(data => {
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
Property 'map' does not exist on type 'Object'.
Run Code Online (Sandbox Code Playgroud)
但应用程序运行良好是正确显示此数据.但这个错误很烦人.
我能做什么?
我按照https://update.angular.io/中给出的步骤进行操作. 升级到Angular 6后,应用程序显示所有路径的空白屏幕.并且浏览器控制台中也没有显示错误.每个路由重定向到默认路径http:// localhost:4200.但http:// localhost:4200/admin工作正常.
任何人都可以帮忙,可能是什么问题?您需要我提供哪些信息才能重现问题?
以下是依赖项列表:
"dependencies": {
"@angular/animations": "6.0.3",
"@angular/cdk": "^6.2.0",
"@angular/common": "6.0.3",
"@angular/compiler": "6.0.3",
"@angular/core": "6.0.3",
"@angular/forms": "6.0.3",
"@angular/http": "6.0.3",
"@angular/material": "^6.2.0",
"@angular/material-moment-adapter": "^6.2.0",
"@angular/platform-browser": "6.0.3",
"@angular/platform-browser-dynamic": "6.0.3",
"@angular/router": "6.0.3",
"@ng-bootstrap/ng-bootstrap": "^2.0.0",
"@ngx-translate/core": "^10.0.2",
"@ngx-translate/http-loader": "^3.0.1",
"@swimlane/ngx-charts": "^8.0.2",
"@types/lodash": "^4.14.87",
"bootstrap": "4.0.0",
"chart.js": "^2.7.2",
"classlist.js": "^1.1.20150312",
"codelyzer": "^4.3.0",
"core-js": "^2.5.1",
"font-awesome": "^4.7.0",
"lodash": "^4.17.4",
"moment": "^2.19.3",
"ng2-charts": "^1.6.0",
"ng2-dragula": "^1.3.1",
"ng2-file-upload": "^1.3.0",
"ng4-charts": "^1.0.2",
"rxjs": "^6.2.0",
"web-animations-js": "^2.2.5",
"zone.js": "^0.8.19"
}, …Run Code Online (Sandbox Code Playgroud) 我创建了一个Angular组件,我在其中导入rxjs do operator.
但是错误无法解决.
ERROR in ./src/app/Members/member-messages/member-messages.component.ts
Module not found: Error: Can't resolve 'rxjs/add/operator/do' in 'C:\Demo\DatingApDemo\DatingApp\src\app\Members\member-messages'
Run Code Online (Sandbox Code Playgroud)
这是什么解决方案?
Sharayu,谢谢你
在为我的角度应用程序提供服务时,我不断收到这些警告:
./src/app/core/containers/navbar/navbar.component.sass
(Emitted value instead of an instance of Error) autoprefixer: ...src\app\core\containers\navbar\navbar.component.sass:11:4: grid-auto-columns is not supported by IE
Run Code Online (Sandbox Code Playgroud)
不幸的是,我对IE支持不感兴趣.是否可以禁用此类警告?
我正在使用Angular 6,当用户按名称单击选项卡加载组件时,我试图按名称动态加载组件,我正在使用以下代码,巫婆在build上运行完美,但在build --production上不起作用
loadTabData(tabname: any) {
this.selectedTab = tabname;
var factories = Array.from(this.resolver["_factories"].keys());
var factoryClass = <Type<any>>(
factories.find((x: any) => x.name === tabname)
);
let viewContainerRef = this.comLoad.viewContainerRef;
viewContainerRef.clear();
const factory = this.resolver.resolveComponentFactory(factoryClass);
let componentRef = viewContainerRef.createComponent(factory);
componentRef.instance.serviceId = this.serviceId;
}
Run Code Online (Sandbox Code Playgroud)
当用户单击选项卡时,我在生产中加载相关组件,则返回以下错误
错误错误:未找到未定义的组件工厂。您是否将其添加到@ NgModule.entryComponents?在e.resolveComponentFactory(main.b98d71b6b5a909371223.js:1)在Wt(main.b98d71b6b5a909371223.js:1)处
我是Angular 6的新手,以前没有任何版本的Angular经验,也没有使用Angular 6创建我的网站的经验,其中我必须显示Spinner直到API Response挂起。我正在使用angular6的httpclient来调用API。我想为每个API请求显示微调框。我搜索了SO,但没有找到问题的答案。以下是我的组件和服务文件。
/* data.services.ts */
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class DataService {
constructor(private http: HttpClient) { }
getUsers() {
return this.http.get('https://jsonplaceholder.typicode.com/users')
}
}
/* users.component.ts *
import { Component, OnInit } from '@angular/core';
import {DataService} from '../data.service';
import { Observable } from 'rxjs';
@Component({
selector: 'app-users',
templateUrl: './users.component.html',
styleUrls: ['./users.component.css']
})
export class UsersComponent implements OnInit {
users$: Object;
constructor(private data: DataService) { …Run Code Online (Sandbox Code Playgroud) 我有一个名为的公共组件PreloaderComponent,我已将其包含在另一个组件中.我需要知道如何将一个变量从父组件传递给它PreloaderComponent,以便*ngIf在模板中使用一个语句.
这是我的代码:
<div id="preloader" *ngIf="loader">
<div id="status">
<div class="spinner"></div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud) 我是angular 6的新手,在这里我尝试在提交数据后重置表单。
一切正常,但是当成功将数据提交到数据库后重置表单时,它将触发表单中所有必需的验证器。
我尝试了很多方法解决这个问题,但是我无法解决。
在这里,在每次提交表单之后,我都想重置表单和所有验证器,然后再在表单字段中输入数据以进行另一次提交。
app.component.html
<form [formGroup]="newMemberForm" (submit)="CreateMember(newMemberForm.value)" novalidate>
....
....
</form>
Run Code Online (Sandbox Code Playgroud)
app.component.ts
this.newMemberForm = this.formBuilder.group({
M_Number: ['', [Validators.required]],
F_Number: ['', [Validators.required]],
M_Name: ['', [Validators.required, Validators.minLength(4)]],
M_Status: ['', [Validators.required]],
M_Dob: ['', [Validators.required]],
M_Sex: ['', [Validators.required]],
});
CreateMember(memberForm) {
this.dmlService.CreateNewMember(memberForm).subscribe(data => {
if (data[0]['RESPONSE'] == 'TRUE')
{
this.newMemberForm.reset();
}
});
}
Run Code Online (Sandbox Code Playgroud)
在这里我重置了触发所需验证器的表单。如果我清除了上述函数中的所有验证器,则当我输入其他表单数据时,验证将无法进行。
在这里,我想在每次提交表单后重设所有验证器和表单,并且想提交下一组表单数据。
谁能帮我解决这个问题。
在阅读本教程时,我遇到了一个奇怪的情况。
在您将服务注入组件中时,如果错过了访问修饰符,则会出现以下错误,但将其添加为私有或公共运行会很好。
如果错过了访问修饰符,我们在Angular中没有任何默认范围吗?
export class UserDetailsComponent implements OnInit {
name="";
lastName="";
constructor(userService : UserServiceService) { }
ngOnInit() {
}
save(){
this.userService.saveUser();
}
}
Run Code Online (Sandbox Code Playgroud)
类型'UserDetailsComponent'上不存在属性'userService'。
我的角度项目中有一个滑动滑块。在桌面视图中有4个项目。我希望在移动设备视图中有1个项目。检查此链接
https://stackblitz.com/edit/ngx-swiper-wrapper-demo-h9egdh?file=app/app.component.ts
演示.ts代码在这里
public slides = [
'First slide',
'Second slide',
'Third slide',
'Fourth slide',
'Fifth slide',
'Sixth slide'
];
public type: string = 'component';
public disabled: boolean = false;
public config: SwiperConfigInterface = {
direction: 'horizontal',
slidesPerView: 4,
keyboard: true,
mousewheel: true,
scrollbar: false,
navigation: true,
pagination: false
};
Run Code Online (Sandbox Code Playgroud)