外部模块的 DI 不工作
DI of external modules not working
我在外部模块的依赖注入方面遇到问题:
export class DealsModel {
foo() {
console.log('foo');
};
}
特别是这段代码:
import 'zone.js';
import 'reflect-metadata';
import 'es6-shim';
import { Component, View, bootstrap } from 'angular2/angular2';
import { DealsModel } from './models/dealsModel';
@Component({
selector: 'search-form',
viewInjector: [DealsModel],
})
@View({
templateUrl: '/Deals/SearchForm'
})
class SearchFormComponent {
constructor(da:DealsModel) {
console.log(da);
}
}
失败,因为生成的 .js(此处部分提交)是:
SearchFormComponent = __decorate([
angular2_1.Component({
selector: 'search-form',
viewInjector: [deals_Model_1.DealsModel],
}),
angular2_1.View({
templateUrl: '/Deals/SearchForm'
}),
__metadata('design:paramtypes', [DealsModel]) // <-- problem
], SearchFormComponent);
return SearchFormComponent;
基本上 __metadata
接收到错误的引用(应该得到 deals_Model_1.DealsModel
),现在可以用这种方法解决:
import 'zone.js';
import 'reflect-metadata';
import 'es6-shim';
import { Component, View, bootstrap } from 'angular2/angular2';
import * as dm from './models/dealsModel';
@Component({
selector: 'search-form',
viewInjector: [dm.DealsModel],
})
@View({
templateUrl: '/Deals/SearchForm'
})
class SearchFormComponent {
constructor(da:dm.DealsModel) {
console.log(da);
}
}
bootstrap(SearchFormComponent);
但这显然是一个 hack。
现在的问题是,我应该提交一个问题还是我遗漏了一些明显的东西?
我正在使用alpha.31
Now the question is, should I submit an issue or am I missing something obvious
已报告并修复:https://github.com/Microsoft/TypeScript/issues/3663
您现在可以使用 ntypescript
来获得此修复:https://github.com/TypeStrong/ntypescript
我在外部模块的依赖注入方面遇到问题:
export class DealsModel {
foo() {
console.log('foo');
};
}
特别是这段代码:
import 'zone.js';
import 'reflect-metadata';
import 'es6-shim';
import { Component, View, bootstrap } from 'angular2/angular2';
import { DealsModel } from './models/dealsModel';
@Component({
selector: 'search-form',
viewInjector: [DealsModel],
})
@View({
templateUrl: '/Deals/SearchForm'
})
class SearchFormComponent {
constructor(da:DealsModel) {
console.log(da);
}
}
失败,因为生成的 .js(此处部分提交)是:
SearchFormComponent = __decorate([
angular2_1.Component({
selector: 'search-form',
viewInjector: [deals_Model_1.DealsModel],
}),
angular2_1.View({
templateUrl: '/Deals/SearchForm'
}),
__metadata('design:paramtypes', [DealsModel]) // <-- problem
], SearchFormComponent);
return SearchFormComponent;
基本上 __metadata
接收到错误的引用(应该得到 deals_Model_1.DealsModel
),现在可以用这种方法解决:
import 'zone.js';
import 'reflect-metadata';
import 'es6-shim';
import { Component, View, bootstrap } from 'angular2/angular2';
import * as dm from './models/dealsModel';
@Component({
selector: 'search-form',
viewInjector: [dm.DealsModel],
})
@View({
templateUrl: '/Deals/SearchForm'
})
class SearchFormComponent {
constructor(da:dm.DealsModel) {
console.log(da);
}
}
bootstrap(SearchFormComponent);
但这显然是一个 hack。 现在的问题是,我应该提交一个问题还是我遗漏了一些明显的东西?
我正在使用alpha.31
Now the question is, should I submit an issue or am I missing something obvious
已报告并修复:https://github.com/Microsoft/TypeScript/issues/3663
您现在可以使用 ntypescript
来获得此修复:https://github.com/TypeStrong/ntypescript