1/*根据查询条件获取数据*/2public getParkInfoByParams(jsonObject: any): Observable<any>{3returnthis.http.request(this.getParkInfoByParamUrl,newRequestOptions({ method: 'GET', body: jsonObject }))4.map((res: Response) =>res.json())5.catch((error: any) => Observable.throw(error || 'S...
我们需要在AppModule顶层中从@angular/common/http 导入HttpClientModule 符号. import { HttpClientModule }from'@angular/common/http' 并在加入@NgModule.imports 数组中。我们将可以在其他的Services中使用。并不需要重复导入。 给service创建一个从服务器获取数据的方法。 getHeroes(): Observable<object>{returnthis...
在组件中定义一个Map对象,并将其初始化: 这里的string表示Map的键类型,any表示值类型,你可以根据实际需求进行调整。 在组件的ngOnInit生命周期钩子中,为Map对象添加键值对: 在组件的ngOnInit生命周期钩子中,为Map对象添加键值对: 在模板中使用*ngFor指令遍历Map对象的键值对: 在模板中使用*ngFor指令遍历Map对象的...
private router: Router) {} canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<true | UrlTree> { // Check whether this user is an administratoor. return this.authService.isAdmin().pipe( map(isAdmin => { if (!isAdmin) { return...
如果是以systemjs的方式打包,安装完成后需要打开systemjs.config.js文件,在System.config的map字段中的最后一行输入以下字段: 代码语言:javascript 复制 'ng2-file-upload': 'npm:ng2-file-upload' 在System.config的packages字段中的最后一行输入: 代码语言:javascript 复制 'ng2-file-upload': { main: 'index.js...
Fixed by creating a function andexportingit that creates an array out of the objectModules, like so: export function joinImports() { return Modules: Object.keys(Modules).map(key => Modules[key]); } ... imports: [ BrowserModule,
import { HttpRequest, HttpClient, HttpHeaders, HttpEvent, HttpEventType, HttpResponse } from '@a...
It requires change in map object and 'packages' as follows: System.config({ map: { // ... rxjs: 'node_modules/rxjs', angular2gridster: 'node_modules/angular2gridster', }, packages: { // ... rxjs: {defaultExtension: 'js'}, angular2gridster: {main: 'dist/index.js', default...
//userApiservice import { Injectable } from '@angular/core'; import { Http } from '@angular/http'; @Injectable() export class UserapiService { constructor(private http:Http) { } /** * 登录 * @param user 用户对象 用户名,密码 */ apilogin(user:object):Promise<any>{ return this.http...
pipe( map((event: HttpEvent<any>) => { if (event instanceof HttpResponse) { console.log('event--->>>', event); } return event; }), catchError((error: HttpErrorResponse) => { if (error.status === 401) { if (error.error.success === false) { this.presentToast('Login failed...