为什么在使用 jquery 查询生成器后 angular2 Lifecycle Hooks 不工作?

Why are angular2 Lifecycle Hooks not working after using jquery query builder?

我在我的项目中导入了 jquery 查询生成器,正如 所说。

ngOnInit() {
this.templateService.getTags(this.contentType)
  .then(tags => {
    this.tags = tags;
  });
}

ngAfterViewInit() {
  this.getQueryBuilder();
}

getQueryBuilder() {
let self = this;
if (self.builder) {
  $(self.builder.nativeElement).queryBuilder({
      plugins: ['bt-tooltip-errors','not-group'],

      filters: [{
          id: 'tag',
          label: 'Tag',
          type: 'string',
          input: 'select',
          values: {
                1: 'Books',
                2: 'Movies',
                3: 'Music',
                4: 'Tools',
                5: 'Goodies',
                6: 'Clothes'
            },
          operators: ['equal']
      }],

      rules: this.rules_basic
  });

}
}

虽然它有效,但 angular 生命周期挂钩不起作用。 总是先到getQueryBuilder()函数,一般先执行ngOnInit(),再执行gAfterViewInit(),自动补全不是working.Why?有人可以帮我吗?非常感谢。

试试这个:

ngOnInit(){
this.templateService.getTags(this.contentType)
  .then(tags => {
    this.tags = tags;
    this.getQueryBuilder();
  });
}

现在只有在 templateService 响应后,this.getQueryBuilder()才会执行