我忙于学习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 })
]);