本文介绍了将 ng-bootstrap 添加到 Angular-CLI 项目时预编译失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试根据 https://stackoverflow.com/a/38413274/将 ng-bootstrap 添加到 Angular-CLI 项目时1596547,我不能不使用 procompile 选项:

When i try to add ng-bootstrap to Angular-CLI project according to https://stackoverflow.com/a/38413274/1596547, i can't not use the procompile option:

import { Component } from '@angular/core';
import {NGB_ALERT_DIRECTIVES,NGB_PRECOMPILE} from '@ng-bootstrap/ng-bootstrap';

@Component({
  moduleId: module.id,
  selector: 'app-root',
  directives: [ NGB_ALERT_DIRECTIVES ],
  precompile: [ NGB_PRECOMPILE ],
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.css']
})
export class AppComponent {
  title = 'app works!';
  public isCollapsed:boolean = false;
}

以上产生以下错误:

Error: Typescript found the following errors:
  /home/bass/testdrive/bootstrap-angular/tmp/broccoli_type_script_compiler-input_base_path-tcvIrPf2.tmp/0/src/app/app.component.ts (9, 3): Argument of type '{ moduleId: string; selector: string; directives: (typeof NgbAlert | typeof NgbDismissibleAlert)[...' is not assignable to parameter of type '{ selector?: string; inputs?: string[]; outputs?: string[]; properties?: string[]; events?: strin...'.
  Object literal may only specify known properties, and 'precompile' does not exist in type '{ selector?: string; inputs?: string[]; outputs?: string[]; properties?: string[]; events?: strin...'.

推荐答案

这似乎是一个版本问题.rc4 中加入了预编译

This seems like a version issue. precompile was added in rc4

通过这个提交:github.com/angular/angular/commit/6c5b653

via this commit: github.com/angular/angular/commit/6c5b653

rc4 变更日志:https://github.com/angular/angular/blob/master/CHANGELOG.md(查看功能)

rc4 changelog: https://github.com/angular/angular/blob/master/CHANGELOG.md (look under features)

这篇关于将 ng-bootstrap 添加到 Angular-CLI 项目时预编译失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 12:18