我忙於學習Angular2,我不知道bind()
和provide()
之間有什麼區別。在我的應用程序中,我似乎找不到任何區別,所以我想知道差異是什麼,以便更好地決定使用哪一個。目前我正在使用最新版本的Angular2:beta17。在Angular2中綁定和提供的區別
例綁定:
import { bootstrap } from 'angular2/platform/browser';
import { ROUTER_PROVIDERS } from 'angular2/router'
import { LocationStrategy, HashLocationStrategy } from 'angular2/platform/common';
import { bind } from 'angular2/core';
// Main Component
import { AppComponent } from './app.component';
bootstrap(AppComponent, [
ROUTER_PROVIDERS,
bind(LocationStrategy).toClass(HashLocationStrategy)
]);
例提供:
import { bootstrap } from 'angular2/platform/browser';
import { ROUTER_PROVIDERS } from 'angular2/router'
import { LocationStrategy, HashLocationStrategy } from 'angular2/platform/common';
import { provide } from 'angular2/core';
// Main Component
import { AppComponent } from './app.component';
bootstrap(AppComponent, [
ROUTER_PROVIDERS,
provide(LocationStrategy, { useClass: HashLocationStrategy })
]);