小编dav*_*ler的帖子

Angular 6组件未显示

我昨天才刚开始学习Angular,所以如果我缺少明显的东西,我深表歉意,但是我试图在app.component.html上显示一个组件,但是它没有出现。

我尝试显示的组件的TS文件:

import { Component, OnInit } from '@angular/core';
import { ImageService } from '../shared/image.service';

@Component({
  selector: 'image-list',
  templateUrl: './image-list.component.html',
  styleUrls: ['./image-list.component.css']
})
export class ImageListComponent implements OnInit {

  images: any[];

  constructor(private _imageService : ImageService ) { }

  searchImages(query : string)
  {
    return this._imageService.getImage(query).subscribe
    (
      data => console.log(data),
      error => console.log(error),
      () => console.log("Request Completed!")
    );
  }

  ngOnInit() {
  } 
}
Run Code Online (Sandbox Code Playgroud)

image-list.component.html:

<button>Find Images</button>
Run Code Online (Sandbox Code Playgroud)

app.component.html:

<image-list></image-list>
Run Code Online (Sandbox Code Playgroud)

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import …
Run Code Online (Sandbox Code Playgroud)

html angular6

5
推荐指数
2
解决办法
1万
查看次数

Google Places API:请求的资源上不存在“Access-Control-Allow-Origin”标头

我尝试从 Angular 应用程序拨打电话,但收到以下错误:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

constructor(private http: Http) { 
  }

getNearbyRestaurants(lat: number, lng: number){
    return this.http.get(this.API_URL+this.API_KEY+`&location=${lat},${lng}`).pipe(
      map(result => result)
        );
      }
    }
Run Code Online (Sandbox Code Playgroud)

有人知道如何解决这个问题吗?谢谢

api rest google-maps google-maps-api-3 google-places-api

0
推荐指数
1
解决办法
2510
查看次数

将AngularJS转换为Angular 6

我对Angular很新,没有使用AngularJS的经验; 但是我发现我要复制的这个codepen:https://codepen.io/anon/pen/jpZBBQ?edit = 0010

我已经修复了模板中的ng-class和ng-click指令,但我被困在了js上; 我从未见过控制器,$scope或者$timeout在Angular 6应用程序中,所以我不知道该怎么做.任何帮助表示赞赏.

javascript angular angular6

0
推荐指数
1
解决办法
937
查看次数