2017-06-19 94 views
0

安裝ngAudio從http://danielstern.github.io/ngAudio/#/。 安裝後,我應該將它包含在app.module.ts中,然後才能在我的項目中使用它。Angular-cli包括ngAudio到您的項目

因爲標準「要求您的項目中的模塊:angular.module('yourModule',['ngAudio'])」在網站上說的話,所以我對如何在這裏包含它感到茫然對我沒有任何意義。

我app.module.ts如下:我使用

//Modules 
import { BrowserModule } from '@angular/platform-browser'; 
import { NgModule } from '@angular/core'; 
import { FormsModule } from '@angular/forms'; 
import { HttpModule } from '@angular/http'; 
import { RouterModule, Route } from '@angular/router'; 

//routes 
const appRoutes: Route[] = 
    [ 
     { path: "soundwave", component: SoundwaveComponent }, 
     { path: "weather", component: WeatherComponent }, 
     { path: "movies", component: MoviesComponent }, 
     { path: "moviesearch", component: MoviesearchComponent }, 
     { path: "news", component: NewsComponent }, 
    ] 

//services 
import { TmdbService } from './services/tmdb.service'; 
import { NewsService } from './services/news.service'; 
import { WeatherService } from './services/weather.service'; 
import { SoundwaveService } from './services/soundwave.service'; 


//Angular Material 
import { MdButtonModule, MdToolbarModule, MdIconModule } from '@angular/material'; 

//special 
import 'hammerjs'; 


//component 
import { AppComponent } from './app.component'; 
import { MoviesComponent } from './movies/movies.component'; 
import { MoviesearchComponent } from './moviesearch/moviesearch.component'; 
import { NewsComponent } from './news/news.component'; 
import { SoundwaveComponent } from './soundwave/soundwave.component'; 
import { WeatherComponent } from './weather/weather.component'; 

//Pipes 
import { RoundPipe } from './pipes/round.pipe'; 
import { SubmitOnEnterDirective } from './directives/submit-on-enter.directive'; 

@NgModule({ 
    declarations: [AppComponent, MoviesComponent, MoviesearchComponent, NewsComponent, SoundwaveComponent, WeatherComponent, RoundPipe, SubmitOnEnterDirective], 
    imports: [BrowserModule, FormsModule, HttpModule, 
     RouterModule.forRoot(appRoutes), 
     MdButtonModule, MdToolbarModule, MdIconModule 
    ], 
    exports: [], 
    providers: [TmdbService, NewsService, WeatherService, SoundwaveService], 
    bootstrap: [AppComponent] 
}) 
export class AppModule { } 

文件夾結構:

enter image description here

+0

這個庫適用於AngularJs,而不是Angular。 – developer033

回答

1

這包是AngularJS,沒有棱角。您將無法輕鬆將其添加到當前項目中。

在Angular中使用音頻比JS更多。 Angular擁有所有的按鈕和服務,但是您需要使用JavaScript處理音頻。我建議使用npm提供的流行JavaScript包。 Howler.js可用,並且可以像任何其他npm軟件包一樣輕鬆地集成到任何Angular-CLI項目中。

您可以查看this安裝問題。

+0

是否還有其他包可供我推薦使用?我正嘗試通過按一個按鈕激活音頻。 – user3110254

+0

已更新的答案。 –

+0

thnx爲答案。我會檢查這個:) – user3110254