我正在尝试将Firebase集成到我的Angular 2应用中,但我一直收到Firebase is not a constructor
的错误。以下是我的所作所为:
bootstrap()
FirebaseService.ts
@Injectable()
export class FirebaseService
{
dataRef: Firebase;
constructor() {
this.dataRef = new Firebase('https://boiling-inferno-1117.firebaseio.com/votes');
}
}
boot.ts
bootstrap(App, [HTTP_PROVIDERS,
ROUTER_PROVIDERS,
IdentityService,
ApiService,
UrlService,
provide(FirebaseService, {useValue: new FirebaseService()})
])
.catch(err => console.error(err));
app.ts
@Component({
selector: 'app',
templateUrl: 'app/app.html',
directives: [AuthRouterOutlet, ROUTER_DIRECTIVES]
})
export class App {
constructor(private firebase:FirebaseService)
{
}
}
Systemjs config:
System.config({
defaultJSExtensions: true,
map: {
'jquery': 'vendors/js/jquery',
'firebase': 'vendors/js/firebase'
},
packages: {
angular2: { defaultExtension: false },
rxjs: { defaultExtension: false }
}
});
并导入Firebase
,如下所示:
import * as Firebase from 'firebase';
非常感谢任何关于如何解决这种情况的建议。
答案 0 :(得分:1)
我会以这种方式配置Firebase:
System.config({
map: {
firebase: '/node_modules/firebase/lib/firebase-web.js',
(...)
},
(...)
});
并在TypeScript文件中将其导入:
import * as Firebase from 'firebase';
有关详细信息,请参阅Angularfire2的文档: