使用帶有角度2的http rest apis所以,我正在通過打字稿在他們的網(wǎng)站上關注角度2指南,并且我陷入了http api集成。我正在嘗試創(chuàng)建一個簡單的應用程序,可以通過soundcloud api搜索一首歌,但是我很難實現(xiàn)和理解如何開始,而且在線資源以很多不同的方式完成它(我相信快速的角度2語法更改)早些時候)。所以目前我的項目看起來像這樣app
components
home
home.component.ts ...
search
search.component.ts ...
app.ts ...
services
soundcloud.ts
bootstrap.ts
index.html在示例中沒有任何花哨的東西,主要文件將是app.tsimport {Component, View} from 'angular2/core';import {RouteConfig, ROUTER_DIRECTIVES} from 'angular2/router';import {HomeComponent} from './home/home.component';import {SearchComponent} from './search/search.component';@Component({
selector: 'app',
templateUrl: 'app/components/app.html',
directives: [ROUTER_DIRECTIVES]})@RouteConfig([
{path: '/home', name: 'Home', component: HomeComponent, useAsDefault: true},
{path: '/search', name: 'Search', component: SearchComponent}])export class App { }bootstrap.ts import {App} from './components/app';import {bootstrap} from 'angular2/platform/browser';import {ROUTER_PROVIDERS} from 'angular2/router';bootstrap(App, [
ROUTER_PROVIDERS]);我試圖找出soundcloud.ts然而我不能和以下方法有錯誤,即@Inject沒有找到(我假設我在這里使用過時的語法)?;旧衔蚁朐谖业膽贸绦虮韱嗡阉鹘M件中使用soundcloud服務進行api調用。import {Injectable} from 'angular2/core'import {Http} from 'angular2/http'@Injectable()export class SoundcloudService {
http : Http
constructor(@Inject(Http) http) {
this.http = http;
}}soundcloud api不包括在這里,因為我不能先得到基礎知識。
使用帶有角度2的http rest apis
MM們
2019-07-27 10:20:07