对于已部署的版本,Angular2依赖继承注入未定义

时间:2017-04-02 07:00:55

标签: angular angular2-services angular2-components

我有一个基本组件类:

export abstract class BaseListComponent<GenObject extends BaseObject> 
{

    constructor(
        @Inject(ActivatedRoute) protected readonly route: ActivatedRoute,
        @Inject(SpudService) protected readonly spud_service: SpudService,
    ) {
        console.log(this.route, this.spud_service);
    }

...
}

许多继承自此类的类使用它,例如:

@Component({
    selector: 'album_list',
    templateUrl: './base-list.component.html',
})
export class AlbumListComponent extends BaseListComponent<AlbumObject> 
{
    ...
}

当我使用ng serve运行此代码并测试一切正常时。如果我使用ng build构建代码并将dist目录复制到Apache服务器,则在没有2个必需参数的情况下调用构造函数。对console.log()的调用会两次打印undefined。当我的代码尝试使用这些未提供的服务时,这会导致预期的致命错误。

我还尝试使用plunker创建一个simple test案例,它完美无缺。

如果在AlbumListComponent中我定义了一个包含所有必需项的构造函数 注射器,它也很完美。

   constructor(
        @Inject(ActivatedRoute) route: ActivatedRoute,
        @Inject(SpudService) spud_service: SpudService,
    ) {
        super(route, spud_service);
        console.log(this.route, this.spud_service);
    }

但我的理解是,这不应该是必需的。应该使用构造函数类和父类的参数 - 因为我没有在派生类中重写它。

在Chrome中,如果我在父类的console.log上设置了一个断点,并查找堆栈跟踪,我可以看到一个函数调用,看起来真的没有提供参数:

function Wrapper_AlbumListComponent() {
  var self = this;
  self._changed = false;
  self._changes = {};
  self.context = new jit_AlbumListComponent0();
  self._expr_0 = jit_CD_INIT_VALUE1;
  self._expr_1 = jit_CD_INIT_VALUE1;
}

我出错的任何想法?

完整代码为available

0 个答案:

没有答案
相关问题